Mir

Merge lp:~raof/mir/dont-kill-the-poor-clients into lp:mir

Proposed by Chris Halse Rogers
Status: Work in progress
Proposed branch: lp:~raof/mir/dont-kill-the-poor-clients
Merge into: lp:mir
Diff against target: 626 lines (+141/-172)
21 files modified
src/client/lifecycle_control.cpp (+13/-0)
src/client/lifecycle_control.h (+2/-0)
src/client/mir_connection.cpp (+11/-0)
src/client/rpc/mir_protobuf_rpc_channel.cpp (+0/-1)
tests/acceptance-tests/test_client_cursor_api.cpp (+0/-2)
tests/acceptance-tests/test_client_input.cpp (+0/-2)
tests/acceptance-tests/test_client_library.cpp (+1/-3)
tests/acceptance-tests/test_large_messages.cpp (+0/-2)
tests/acceptance-tests/test_nested_mir.cpp (+0/-2)
tests/acceptance-tests/test_prompt_session_client_api.cpp (+0/-2)
tests/acceptance-tests/test_protobuf.cpp (+0/-2)
tests/acceptance-tests/test_test_framework.cpp (+0/-2)
tests/include/mir_test_framework/basic_client_server_fixture.h (+0/-2)
tests/include/mir_test_framework/using_stub_client_platform.h (+0/-51)
tests/integration-tests/client/test_client_render.cpp (+0/-10)
tests/mir_test_framework/CMakeLists.txt (+0/-1)
tests/mir_test_framework/testing_process_manager.cpp (+0/-2)
tests/mir_test_framework/using_stub_client_platform.cpp (+0/-81)
tests/unit-tests/client/CMakeLists.txt (+1/-0)
tests/unit-tests/client/test_client_mir_surface.cpp (+2/-7)
tests/unit-tests/client/test_lifecycle_control.cpp (+111/-0)
To merge this branch: bzr merge lp:~raof/mir/dont-kill-the-poor-clients
Reviewer Review Type Date Requested Status
PS Jenkins bot (community) continuous-integration Needs Fixing
Daniel van Vugt Needs Fixing
Chris Halse Rogers Abstain
Cemil Azizoglu (community) Approve
Alexandros Frantzis (community) Approve
Review via email: mp+232971@code.launchpad.net

Commit message

Don't call the default lifecycle handler after mir_connection_release

The client has deliberately disconnected; they don't need a SIGHUP to kill them because they've been disconnected.

Clients which set a non-default lifecycle handler still get their mir_lifecycle_connection_lost event, as normal.

Description of the change

Don't call the default lifecycle handler during connection cleanup when the client explicitly calls mir_connection_release. They've deliberately disconnected; they don't also need a SIGHUP.

To post a comment you must log in.
1886. By Chris Halse Rogers

Also remove unnecessary lifecycle setting in Android integration tests

1887. By Chris Halse Rogers

Remove some detritus

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

Why are we removing UsingStubClientPlatform? Apart from the mir_connection_release() workaround in it (which was a recent addition), it stubs out the client platform which is needed by most tests (since the server platform is also stubbed out).

We should just remove the mir_connection_release() workaround from UsingStubPlatform.

Needs Fixing/Information

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

But it doesn't stub out the client platform?

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

Hm. Expanding on that - it tries, but fails, to stub out the client platform. It's got at configuration() override, but this is never called.

The DefaultConnectionAPI is constructed in mir_connection_api.cpp, and that uses DefaultMirConnectionAPI's configuration().

Then UsingStubClientPlatform comes along, and interposes StubMirConnectionAPI's connect() method before the default, but then calls the default API's connect(), which calls DefaultConfigurationAPI's configuration().

Since UsingStubClientPlatform wasn't actually doing anything, I removed it.

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

> Hm. Expanding on that - it tries, but fails, to stub out the client platform. It's got at
> configuration() override, but this is never called.

Wow, you are right, super-not-inheritance-fail there. Thanks for catching this.

OK, so as long as our tests work without a stubbed platform that's fine. We can add a proper implementation of this as needed.

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: Needs Fixing (continuous-integration)
Revision history for this message
Cemil Azizoglu (cemil-azizoglu) wrote :

LGTM

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

I like it, but not all clients shut down cleanly after applying this branch:

$ bin/mir_demo_client_egltriangle
Current active output is 1920x1200 +0+0
Server supports 2 of 6 surface pixel formats. Using format: 4
Surface occluded
libEGL warning: unsupported platform (null)
Surface 0 DPI
Surface exposed
1 FPS
23 FPS
60 FPS
60 FPS
Surface occluded
Signal 1 received. Good night.
Caught exception at Mir/EGL driver boundary: /home/dan/bzr/mir/tmp.poor/src/client/rpc/stream_socket_transport.cpp(276): Throw in function virtual void mir::client::rpc::StreamSocketTransport::send_data(const std::vector<unsigned char>&)
Dynamic exception type: N5boost16exception_detail10clone_implINS0_19error_info_injectorIN12_GLOBAL__N_125socket_disconnected_errorEEEEE
std::exception::what: Failed to send message to server: Broken pipe
32, "Broken pipe"

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

To clarify: The regression is the exception. That doesn't happen using development-branch.

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

I'm confused as to how you're getting the “Signal 1 received” message; signal 1 is SIGHUP, which we no longer send?

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

I tested the branch by merging into development-branch of course...

Just kill the server and the clients receive SIGHUP. In the case of egltriangle it also throws the exception...

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

(1) The exception regression described above needs fixing.

and also now:

(2) Text conflict in tests/acceptance-tests/test_client_input.cpp
1 conflicts encountered.

review: Needs Fixing
1888. By Chris Halse Rogers

Detect server disconnect in example EGL apps

1889. By Chris Halse Rogers

Merge trunk, resolving conflicts

1890. By Chris Halse Rogers

Remove last vestages of UsingStubClientPlatform that crept back 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
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)
1891. By Chris Halse Rogers

Merge trunk, resolving conflicts

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

(3) examples/eglapp.c: Please revert the changes to examples/*. They're just hiding the aforementioned regression instead of fixing it. An unmodified client will still suffer from the same regression so it's better to not introduce it than to let it land and then need to create/fix a new bug.

Signal 1 received. Good night.
Caught exception at Mir/EGL driver boundary: /home/dan/bzr/mir/tmp.poor/src/client/rpc/stream_socket_transport.cpp(280): Throw in function virtual void mir::client::rpc::StreamSocketTransport::send_data(const std::vector<unsigned char>&)
Dynamic exception type: N5boost16exception_detail10clone_implINS0_19error_info_injectorIN12_GLOBAL__N_112socket_errorEEEEE
std::exception::what: Failed to send message to server: Bad file descriptor
9, "Bad file descriptor"

review: Needs Fixing
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Chris Halse Rogers (raof) wrote :

So, I can't reproduce the exception you see after reverting the changes to eglapp.c.

I think we want to have a discussion about appropriate error handling on the 2/3rds call today :)

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

Ok. So, as I mentioned on the 2/3rds call, this merge proposal doesn't change the code around the exception that you're seeing, which looks to be a race between the signal handler setting ‘running = false’ and the eglSwapBuffers call making a advance_buffer call. I can't reproduce it at the moment.

It isn't an exception escaping across to our C clients, and it's an inherent limitation in eglapp's use of a running flag.

This error is propagated through to clients by eglSwapBuffers returning false, but we don't do anything with that in eglapp.c

review: Abstain
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
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
1892. By Chris Halse Rogers

Merge trunk, resolving conflicts

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

Today I can't reproduce the exception regression either.

Although I suggest it's still a good idea to revert the examples/* changes. They're not strictly related to what's being fixed according to the description. And it's extra-useful to leave the default behaviour in there so we will see it in case the exception problem returns.

review: Needs Fixing
1893. By Chris Halse Rogers

Revert eglapp changes.

These will be proposed as a part of a wider cleanup of our examples

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 :

Approved in theory, but now the Jenkins failures appear to be a real regression, easy to reproduce:

$ umockdev-run -- valgrind bin/mir_unit_tests
...
[ RUN ] MirClientSurfaceTest.client_buffer_created_on_next_buffer
pure virtual method called
terminate called without an active exception

or

$ umockdev-run -- valgrind bin/mir_unit_tests --gtest_filter="MirClientSurfaceTest.*"
...
[ RUN ] MirClientSurfaceTest.create_wait_handle_really_blocks
pure virtual method called
terminate called without an active exception

review: Needs Fixing
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
1894. By Chris Halse Rogers

Don't force the completion of pending RPC calls on disconnect.

There's nothing sensible to be done there. If the client is simple, they'll be killed with a signal
(that awesomely might race with our force_completion() on the IO thread).

If the client is complex, they'll have a handler for the disconnect.

In neither case is it useful to call the RPC response handlers with a garbage non-reply.
Our response handlers are not generally capable of handling invalid protobuf::Message objects,
so this frequently results in calling a pure-virtual function and termination.

At best this would result in calling a client callback with an error object. But the client
already knows that the connection has died (or the process has been killed by a signal)
so that's not super-useful.

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

The first "regression" I was talking about seems to be bug 1368652. Indeed not caused by this branch.

The second (actual) regression that was causing Jenkins failures... I guess we shall see soon if that's fixed.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Chris Halse Rogers (raof) wrote :

Urgh. I am the master of submitting branches that require significant infrastructure changes before the entirely work.

Unmerged revisions

1894. By Chris Halse Rogers

Don't force the completion of pending RPC calls on disconnect.

There's nothing sensible to be done there. If the client is simple, they'll be killed with a signal
(that awesomely might race with our force_completion() on the IO thread).

If the client is complex, they'll have a handler for the disconnect.

In neither case is it useful to call the RPC response handlers with a garbage non-reply.
Our response handlers are not generally capable of handling invalid protobuf::Message objects,
so this frequently results in calling a pure-virtual function and termination.

At best this would result in calling a client callback with an error object. But the client
already knows that the connection has died (or the process has been killed by a signal)
so that's not super-useful.

1893. By Chris Halse Rogers

Revert eglapp changes.

These will be proposed as a part of a wider cleanup of our examples

1892. By Chris Halse Rogers

Merge trunk, resolving conflicts

1891. By Chris Halse Rogers

Merge trunk, resolving conflicts

1890. By Chris Halse Rogers

Remove last vestages of UsingStubClientPlatform that crept back in

1889. By Chris Halse Rogers

Merge trunk, resolving conflicts

1888. By Chris Halse Rogers

Detect server disconnect in example EGL apps

1887. By Chris Halse Rogers

Remove some detritus

1886. By Chris Halse Rogers

Also remove unnecessary lifecycle setting in Android integration tests

1885. By Chris Halse Rogers

Remove UsingStubClientConnection.

This is now superfluous; it was only preventing the test code from being SIGHUPed when
it called mir_connection_release, which we no longer do.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/client/lifecycle_control.cpp'
2--- src/client/lifecycle_control.cpp 2013-10-07 09:27:32 +0000
3+++ src/client/lifecycle_control.cpp 2014-09-12 08:09:04 +0000
4@@ -36,6 +36,19 @@
5 handle_lifecycle_event = fn;
6 }
7
8+void mir::client::LifecycleControl::replace_lifecycle_event_handler_if_matches(
9+ void (*match)(MirLifecycleState),
10+ const std::function<void (MirLifecycleState)> &new_handler)
11+{
12+ std::lock_guard<decltype(guard)> lock(guard);
13+
14+ auto current_target = handle_lifecycle_event.target<void(*)(MirLifecycleState)>();
15+ if (current_target && *current_target == match)
16+ {
17+ handle_lifecycle_event = new_handler;
18+ }
19+}
20+
21 void mcl::LifecycleControl::call_lifecycle_event_handler(uint32_t state)
22 {
23 std::unique_lock<std::mutex> lk(guard);
24
25=== modified file 'src/client/lifecycle_control.h'
26--- src/client/lifecycle_control.h 2013-08-23 12:23:47 +0000
27+++ src/client/lifecycle_control.h 2014-09-12 08:09:04 +0000
28@@ -35,6 +35,8 @@
29 ~LifecycleControl();
30
31 void set_lifecycle_event_handler(std::function<void(MirLifecycleState)> const&);
32+ void replace_lifecycle_event_handler_if_matches(void(*match)(MirLifecycleState),
33+ std::function<void(MirLifecycleState)> const& new_handler);
34 void call_lifecycle_event_handler(uint32_t state);
35
36 private:
37
38=== modified file 'src/client/mir_connection.cpp'
39--- src/client/mir_connection.cpp 2014-09-10 12:50:53 +0000
40+++ src/client/mir_connection.cpp 2014-09-12 08:09:04 +0000
41@@ -298,9 +298,20 @@
42 disconnect_wait_handle.result_received();
43 }
44
45+namespace
46+{
47+void null_lifecycle_handler(MirLifecycleState)
48+{
49+}
50+}
51+
52 MirWaitHandle* MirConnection::disconnect()
53 {
54 disconnect_wait_handle.expect_result();
55+ // Don't kill the client with a signal on disconnect when the client has explicitly
56+ // requested disconnection.
57+ lifecycle_control->replace_lifecycle_event_handler_if_matches(&default_lifecycle_event_handler,
58+ &null_lifecycle_handler);
59 server.disconnect(0, &ignored, &ignored,
60 google::protobuf::NewCallback(this, &MirConnection::done_disconnect));
61
62
63=== modified file 'src/client/rpc/mir_protobuf_rpc_channel.cpp'
64--- src/client/rpc/mir_protobuf_rpc_channel.cpp 2014-09-10 12:50:53 +0000
65+++ src/client/rpc/mir_protobuf_rpc_channel.cpp 2014-09-12 08:09:04 +0000
66@@ -79,7 +79,6 @@
67 {
68 lifecycle_control->call_lifecycle_event_handler(mir_lifecycle_connection_lost);
69 }
70- pending_calls.force_completion();
71 }
72
73
74
75=== modified file 'tests/acceptance-tests/test_client_cursor_api.cpp'
76--- tests/acceptance-tests/test_client_cursor_api.cpp 2014-09-10 12:50:53 +0000
77+++ tests/acceptance-tests/test_client_cursor_api.cpp 2014-09-12 08:09:04 +0000
78@@ -24,7 +24,6 @@
79 #include "mir_test_framework/in_process_server.h"
80 #include "mir_test_framework/fake_event_hub_server_configuration.h"
81 #include "mir_test_framework/declarative_placement_strategy.h"
82-#include "mir_test_framework/using_stub_client_platform.h"
83
84 #include "mir_test/fake_shared.h"
85 #include "mir_test/spin_wait.h"
86@@ -264,7 +263,6 @@
87 std::string const client_cursor_2{"cursor-2"};
88 TestServerConfiguration server_configuration_;
89 mir::test::WaitCondition expectations_satisfied;
90- mtf::UsingStubClientPlatform using_stub_client_platform;
91 };
92
93 }
94
95=== modified file 'tests/acceptance-tests/test_client_input.cpp'
96--- tests/acceptance-tests/test_client_input.cpp 2014-09-10 12:50:53 +0000
97+++ tests/acceptance-tests/test_client_input.cpp 2014-09-12 08:09:04 +0000
98@@ -25,7 +25,6 @@
99 #include "src/server/scene/session_container.h"
100
101 #include "mir_test_framework/in_process_server.h"
102-#include "mir_test_framework/using_stub_client_platform.h"
103 #include "mir_test_framework/fake_event_hub_server_configuration.h"
104 #include "mir_test_framework/declarative_placement_strategy.h"
105 #include "mir_test/wait_condition.h"
106@@ -213,7 +212,6 @@
107 std::string const test_client_name_2{"client2"};
108 geom::Rectangle const screen_geometry{{0, 0}, {1000, 800}};
109 TestServerConfiguration server_configuration_{screen_geometry};
110- mtf::UsingStubClientPlatform using_stub_client_platform;
111 };
112
113 }
114
115=== modified file 'tests/acceptance-tests/test_client_library.cpp'
116--- tests/acceptance-tests/test_client_library.cpp 2014-09-10 12:50:53 +0000
117+++ tests/acceptance-tests/test_client_library.cpp 2014-09-12 08:09:04 +0000
118@@ -21,7 +21,6 @@
119
120 #include "mir_test_framework/stubbed_server_configuration.h"
121 #include "mir_test_framework/in_process_server.h"
122-#include "mir_test_framework/using_stub_client_platform.h"
123
124 #include "src/client/client_buffer.h"
125
126@@ -60,7 +59,6 @@
127 {
128 mtf::StubbedServerConfiguration server_configuration;
129 mir::DefaultServerConfiguration& server_config() override { return server_configuration; }
130- mtf::UsingStubClientPlatform using_stub_client_platform;
131
132 std::set<MirSurface*> surfaces;
133 MirConnection* connection = nullptr;
134@@ -640,7 +638,7 @@
135 mir_connection_release(connection);
136 }
137
138-TEST_F(ClientLibrary, MultiSurfaceClientTracksBufferFdsCorrectly)
139+TEST_F(ClientLibrary, multi_surface_client_tracks_buffer_fds_correctly)
140 {
141 mir_wait_for(mir_connect(new_connection().c_str(), __PRETTY_FUNCTION__, connection_callback, this));
142
143
144=== modified file 'tests/acceptance-tests/test_large_messages.cpp'
145--- tests/acceptance-tests/test_large_messages.cpp 2014-09-10 12:50:53 +0000
146+++ tests/acceptance-tests/test_large_messages.cpp 2014-09-12 08:09:04 +0000
147@@ -18,7 +18,6 @@
148
149 #include "mir_test_framework/in_process_server.h"
150 #include "mir_test_framework/stubbed_server_configuration.h"
151-#include "mir_test_framework/using_stub_client_platform.h"
152 #include "mir_test/wait_object.h"
153 #include "mir_test/fake_shared.h"
154 #include "mir_test_doubles/stub_display_configuration.h"
155@@ -68,7 +67,6 @@
156 return large_messages_server_config;
157 }
158
159- mir_test_framework::UsingStubClientPlatform using_stub_client_platform;
160 };
161
162 struct ConnectionContext
163
164=== modified file 'tests/acceptance-tests/test_nested_mir.cpp'
165--- tests/acceptance-tests/test_nested_mir.cpp 2014-09-10 12:50:53 +0000
166+++ tests/acceptance-tests/test_nested_mir.cpp 2014-09-12 08:09:04 +0000
167@@ -28,7 +28,6 @@
168
169 #include "mir_test_framework/in_process_server.h"
170 #include "mir_test_framework/stubbed_server_configuration.h"
171-#include "mir_test_framework/using_stub_client_platform.h"
172 #include "mir_test/wait_condition.h"
173
174 #include "mir_test_doubles/mock_egl.h"
175@@ -267,7 +266,6 @@
176 NestedServer() : HostServerConfiguration(display_geometry) {}
177
178 NestedMockEGL mock_egl;
179- mtf::UsingStubClientPlatform using_stub_client_platform;
180
181 virtual mir::DefaultServerConfiguration& server_config()
182 {
183
184=== modified file 'tests/acceptance-tests/test_prompt_session_client_api.cpp'
185--- tests/acceptance-tests/test_prompt_session_client_api.cpp 2014-09-10 12:50:53 +0000
186+++ tests/acceptance-tests/test_prompt_session_client_api.cpp 2014-09-12 08:09:04 +0000
187@@ -28,7 +28,6 @@
188 #include "mir_test_doubles/stub_session_authorizer.h"
189 #include "mir_test_framework/stubbed_server_configuration.h"
190 #include "mir_test_framework/in_process_server.h"
191-#include "mir_test_framework/using_stub_client_platform.h"
192 #include "mir_test/popen.h"
193
194 #include <gtest/gtest.h>
195@@ -142,7 +141,6 @@
196 std::shared_ptr<mf::Session> application_session;
197
198 std::shared_ptr<ms::PromptSession> server_prompt_session;
199- mtf::UsingStubClientPlatform using_stub_client_platform;
200
201 void SetUp() override
202 {
203
204=== modified file 'tests/acceptance-tests/test_protobuf.cpp'
205--- tests/acceptance-tests/test_protobuf.cpp 2014-09-10 21:37:08 +0000
206+++ tests/acceptance-tests/test_protobuf.cpp 2014-09-12 08:09:04 +0000
207@@ -26,7 +26,6 @@
208
209 #include "mir_test_framework/stubbed_server_configuration.h"
210 #include "mir_test_framework/in_process_server.h"
211-#include "mir_test_framework/using_stub_client_platform.h"
212
213 #include <gtest/gtest.h>
214 #include <gmock/gmock.h>
215@@ -158,7 +157,6 @@
216 mir::DefaultServerConfiguration& server_config() override { return my_server_config; }
217
218 DemoServerConfiguration my_server_config;
219- mtf::UsingStubClientPlatform using_stub_client_platform;
220
221 std::shared_ptr<DemoConnectionCreator> demo_connection_creator;
222
223
224=== modified file 'tests/acceptance-tests/test_test_framework.cpp'
225--- tests/acceptance-tests/test_test_framework.cpp 2014-09-10 12:50:53 +0000
226+++ tests/acceptance-tests/test_test_framework.cpp 2014-09-12 08:09:04 +0000
227@@ -19,7 +19,6 @@
228 #include "mir_test_framework/display_server_test_fixture.h"
229 #include "mir_test_framework/testing_server_configuration.h"
230 #include "mir_test_framework/in_process_server.h"
231-#include "mir_test_framework/using_stub_client_platform.h"
232
233 #include "mir_toolkit/mir_client_library.h"
234
235@@ -75,7 +74,6 @@
236 virtual mir::DefaultServerConfiguration& server_config() { return server_config_; }
237
238 mir_test_framework::StubbedServerConfiguration server_config_;
239- mir_test_framework::UsingStubClientPlatform using_stub_client_platform;
240 };
241 }
242
243
244=== modified file 'tests/include/mir_test_framework/basic_client_server_fixture.h'
245--- tests/include/mir_test_framework/basic_client_server_fixture.h 2014-09-10 12:50:53 +0000
246+++ tests/include/mir_test_framework/basic_client_server_fixture.h 2014-09-12 08:09:04 +0000
247@@ -22,7 +22,6 @@
248 #include "mir_toolkit/mir_client_library.h"
249
250 #include "mir_test_framework/in_process_server.h"
251-#include "mir_test_framework/using_stub_client_platform.h"
252
253 #include "boost/throw_exception.hpp"
254
255@@ -34,7 +33,6 @@
256 struct BasicClientServerFixture : InProcessServer
257 {
258 TestServerConfiguration server_configuration;
259- UsingStubClientPlatform using_stub_client_platform;
260
261 mir::DefaultServerConfiguration& server_config() override { return server_configuration; }
262
263
264=== removed file 'tests/include/mir_test_framework/using_stub_client_platform.h'
265--- tests/include/mir_test_framework/using_stub_client_platform.h 2014-09-10 12:50:53 +0000
266+++ tests/include/mir_test_framework/using_stub_client_platform.h 1970-01-01 00:00:00 +0000
267@@ -1,51 +0,0 @@
268-/*
269- * Copyright © 2014 Canonical Ltd.
270- *
271- * This program is free software: you can redistribute it and/or modify it
272- * under the terms of the GNU General Public License version 3,
273- * as published by the Free Software Foundation.
274- *
275- * This program is distributed in the hope that it will be useful,
276- * but WITHOUT ANY WARRANTY; without even the implied warranty of
277- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
278- * GNU General Public License for more details.
279- *
280- * You should have received a copy of the GNU General Public License
281- * along with this program. If not, see <http://www.gnu.org/licenses/>.
282- *
283- * Authored by: Alexandros Frantzis <alexandros.frantzis@canonical.com>
284- */
285-
286-#ifndef MIR_TEST_FRAMEWORK_USING_STUB_CLIENT_PLATFORM_H_
287-#define MIR_TEST_FRAMEWORK_USING_STUB_CLIENT_PLATFORM_H_
288-
289-#include <memory>
290-
291-namespace mir
292-{
293-namespace client
294-{
295-class MirConnectionAPI;
296-}
297-}
298-
299-namespace mir_test_framework
300-{
301-
302-class UsingStubClientPlatform
303-{
304-public:
305- UsingStubClientPlatform();
306- ~UsingStubClientPlatform();
307-
308-private:
309- UsingStubClientPlatform(UsingStubClientPlatform const&) = delete;
310- UsingStubClientPlatform operator=(UsingStubClientPlatform const&) = delete;
311-
312- mir::client::MirConnectionAPI* prev_api;
313- std::unique_ptr<mir::client::MirConnectionAPI> stub_api;
314-};
315-
316-}
317-
318-#endif /* MIR_TEST_FRAMEWORK_USING_STUB_CLIENT_PLATFORM_H_ */
319
320=== modified file 'tests/integration-tests/client/test_client_render.cpp'
321--- tests/integration-tests/client/test_client_render.cpp 2014-09-10 13:27:58 +0000
322+++ tests/integration-tests/client/test_client_render.cpp 2014-09-12 08:09:04 +0000
323@@ -57,10 +57,6 @@
324 static mtd::DrawPatternCheckered<2,2> draw_pattern1(pattern1);
325 static const char socket_file[] = "./test_client_ipc_render_socket";
326
327-void null_lifecycle_callback(MirConnection*, MirLifecycleState, void*)
328-{
329-}
330-
331 struct TestClient
332 {
333 static MirPixelFormat select_format_for_visual_id(int visual_id)
334@@ -114,9 +110,6 @@
335 }
336
337 mir_surface_release_sync(surface);
338- // Clear the lifecycle callback in order not to get SIGHUP by the
339- // default lifecycle handler during connection teardown
340- mir_connection_set_lifecycle_event_callback(connection, null_lifecycle_callback, nullptr);
341 mir_connection_release(connection);
342 return 0;
343 }
344@@ -174,9 +167,6 @@
345 }
346
347 mir_surface_release_sync(mir_surface);
348- // Clear the lifecycle callback in order not to get SIGHUP by the
349- // default lifecycle handler during connection teardown
350- mir_connection_set_lifecycle_event_callback(connection, null_lifecycle_callback, nullptr);
351 mir_connection_release(connection);
352 return 0;
353 }
354
355=== modified file 'tests/mir_test_framework/CMakeLists.txt'
356--- tests/mir_test_framework/CMakeLists.txt 2014-09-10 12:50:53 +0000
357+++ tests/mir_test_framework/CMakeLists.txt 2014-09-12 08:09:04 +0000
358@@ -19,7 +19,6 @@
359 testing_client_options.cpp
360 display_server_test_fixture.cpp
361 process.cpp
362- using_stub_client_platform.cpp
363 udev_environment.cpp
364 declarative_placement_strategy.cpp
365 fake_event_hub_server_configuration.cpp
366
367=== modified file 'tests/mir_test_framework/testing_process_manager.cpp'
368--- tests/mir_test_framework/testing_process_manager.cpp 2014-09-10 12:50:53 +0000
369+++ tests/mir_test_framework/testing_process_manager.cpp 2014-09-12 08:09:04 +0000
370@@ -19,7 +19,6 @@
371 #include "mir_toolkit/client_types.h"
372 #include "mir_test_framework/testing_process_manager.h"
373 #include "mir_test_framework/detect_server.h"
374-#include "mir_test_framework/using_stub_client_platform.h"
375 #include "src/client/mir_connection.h"
376 #include "mir/run_mir.h"
377
378@@ -107,7 +106,6 @@
379 SCOPED_TRACE("Client");
380 if (!config.use_real_graphics(test_options))
381 {
382- mtf::UsingStubClientPlatform p;
383 config.exec();
384 }
385 else
386
387=== removed file 'tests/mir_test_framework/using_stub_client_platform.cpp'
388--- tests/mir_test_framework/using_stub_client_platform.cpp 2014-09-10 12:50:53 +0000
389+++ tests/mir_test_framework/using_stub_client_platform.cpp 1970-01-01 00:00:00 +0000
390@@ -1,81 +0,0 @@
391-/*
392- * Copyright © 2014 Canonical Ltd.
393- *
394- * This program is free software: you can redistribute it and/or modify it
395- * under the terms of the GNU General Public License version 3,
396- * as published by the Free Software Foundation.
397- *
398- * This program is distributed in the hope that it will be useful,
399- * but WITHOUT ANY WARRANTY; without even the implied warranty of
400- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
401- * GNU General Public License for more details.
402- *
403- * You should have received a copy of the GNU General Public License
404- * along with this program. If not, see <http://www.gnu.org/licenses/>.
405- *
406- * Authored by: Alexandros Frantzis <alexandros.frantzis@canonical.com>
407- */
408-
409-#include "mir_test_framework/using_stub_client_platform.h"
410-#include "mir_test_framework/stub_client_connection_configuration.h"
411-#include "mir_toolkit/mir_client_library.h"
412-#include "src/client/mir_connection_api.h"
413-
414-namespace mtf = mir_test_framework;
415-namespace mcl = mir::client;
416-
417-namespace
418-{
419-
420-void null_lifecycle_callback(MirConnection*, MirLifecycleState, void*)
421-{
422-}
423-
424-class StubMirConnectionAPI : public mcl::MirConnectionAPI
425-{
426-public:
427- StubMirConnectionAPI(mcl::MirConnectionAPI* prev_api)
428- : prev_api{prev_api}
429- {
430- }
431-
432- MirWaitHandle* connect(
433- char const* socket_file,
434- char const* name,
435- mir_connected_callback callback,
436- void* context) override
437- {
438- return prev_api->connect(socket_file, name, callback, context);
439- }
440-
441- void release(MirConnection* connection) override
442- {
443- // Clear the lifecycle callback in order not to get SIGHUP by the
444- // default lifecycle handler during connection teardown
445- mir_connection_set_lifecycle_event_callback(connection, null_lifecycle_callback, nullptr);
446- return prev_api->release(connection);
447- }
448-
449- std::unique_ptr<mcl::ConnectionConfiguration> configuration(std::string const& socket) override
450- {
451- return std::unique_ptr<mcl::ConnectionConfiguration>{
452- new mtf::StubConnectionConfiguration{socket}};
453- }
454-
455-private:
456- mcl::MirConnectionAPI* const prev_api;
457-};
458-
459-}
460-
461-mtf::UsingStubClientPlatform::UsingStubClientPlatform()
462- : prev_api{mir_connection_api_impl},
463- stub_api{new StubMirConnectionAPI{prev_api}}
464-{
465- mir_connection_api_impl = stub_api.get();
466-}
467-
468-mtf::UsingStubClientPlatform::~UsingStubClientPlatform()
469-{
470- mir_connection_api_impl = prev_api;
471-}
472
473=== modified file 'tests/unit-tests/client/CMakeLists.txt'
474--- tests/unit-tests/client/CMakeLists.txt 2014-09-10 12:50:53 +0000
475+++ tests/unit-tests/client/CMakeLists.txt 2014-09-12 08:09:04 +0000
476@@ -12,6 +12,7 @@
477 ${CMAKE_CURRENT_SOURCE_DIR}/test_protobuf_rpc_channel.cpp
478 ${CMAKE_CURRENT_SOURCE_DIR}/test_mir_prompt_session.cpp
479 ${CMAKE_CURRENT_SOURCE_DIR}/test_event_distributor.cpp
480+ ${CMAKE_CURRENT_SOURCE_DIR}/test_lifecycle_control.cpp
481 ${CMAKE_CURRENT_SOURCE_DIR}/test_periodic_perf_report.cpp
482 )
483
484
485=== modified file 'tests/unit-tests/client/test_client_mir_surface.cpp'
486--- tests/unit-tests/client/test_client_mir_surface.cpp 2014-09-10 12:50:53 +0000
487+++ tests/unit-tests/client/test_client_mir_surface.cpp 2014-09-12 08:09:04 +0000
488@@ -392,10 +392,6 @@
489 {
490 }
491
492-void null_lifecycle_callback(MirConnection*, MirLifecycleState, void*)
493-{
494-}
495-
496 MATCHER_P(BufferPackageMatches, package, "")
497 {
498 // Can't simply use memcmp() on the whole struct because age is not sent over the wire
499@@ -421,9 +417,8 @@
500
501 ~MirClientSurfaceTest()
502 {
503- // Clear the lifecycle callback in order not to get SIGHUP by the
504- // default lifecycle handler during connection teardown
505- connection->register_lifecycle_event_callback(null_lifecycle_callback, nullptr);
506+ // Clean up nicely after ourselves...
507+ connection->disconnect();
508 }
509
510 void start_test_server()
511
512=== added file 'tests/unit-tests/client/test_lifecycle_control.cpp'
513--- tests/unit-tests/client/test_lifecycle_control.cpp 1970-01-01 00:00:00 +0000
514+++ tests/unit-tests/client/test_lifecycle_control.cpp 2014-09-12 08:09:04 +0000
515@@ -0,0 +1,111 @@
516+/*
517+ * Copyright © 2014 Canonical Ltd.
518+ *
519+ * This program is free software: you can redistribute it and/or modify
520+ * it under the terms of the GNU General Public License version 3 as
521+ * published by the Free Software Foundation.
522+ *
523+ * This program is distributed in the hope that it will be useful,
524+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
525+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
526+ * GNU General Public License for more details.
527+ *
528+ * You should have received a copy of the GNU General Public License
529+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
530+ *
531+ * Authored by: Christopher James Halse Rogers <christopher.halse.rogers@canonical.com>
532+ */
533+
534+#include "src/client/lifecycle_control.h"
535+
536+#include <gtest/gtest.h>
537+
538+namespace
539+{
540+bool a_called{false}, b_called{false};
541+
542+void handler_a(MirLifecycleState)
543+{
544+ a_called = true;
545+}
546+
547+void handler_b(MirLifecycleState)
548+{
549+ b_called = true;
550+}
551+}
552+
553+TEST(LifeCycleControl, InvokesSetTarget)
554+{
555+ mir::client::LifecycleControl control;
556+
557+ a_called = false;
558+ b_called = false;
559+
560+ control.set_lifecycle_event_handler(&handler_a);
561+ control.call_lifecycle_event_handler(mir_lifecycle_connection_lost);
562+
563+ EXPECT_TRUE(a_called);
564+ EXPECT_FALSE(b_called);
565+}
566+
567+TEST(LifeCycleControl, InvokesUpdatedTarget)
568+{
569+ mir::client::LifecycleControl control;
570+
571+ a_called = false;
572+ b_called = false;
573+
574+ control.set_lifecycle_event_handler(&handler_a);
575+ control.set_lifecycle_event_handler(&handler_b);
576+ control.call_lifecycle_event_handler(mir_lifecycle_state_resumed);
577+
578+ EXPECT_FALSE(a_called);
579+ EXPECT_TRUE(b_called);
580+}
581+
582+TEST(LifeCycleControl, UpdateReplacesIfMatches)
583+{
584+ mir::client::LifecycleControl control;
585+
586+ a_called = false;
587+ b_called = false;
588+
589+ control.set_lifecycle_event_handler(&handler_a);
590+ control.replace_lifecycle_event_handler_if_matches(&handler_a, &handler_b);
591+ control.call_lifecycle_event_handler(mir_lifecycle_state_resumed);
592+
593+ EXPECT_FALSE(a_called);
594+ EXPECT_TRUE(b_called);
595+}
596+
597+TEST(LifeCycleControl, UpdateDoesNotReplaceIfNotMatching)
598+{
599+ mir::client::LifecycleControl control;
600+
601+ a_called = false;
602+ b_called = false;
603+
604+ control.set_lifecycle_event_handler(&handler_a);
605+ control.replace_lifecycle_event_handler_if_matches(&handler_b, &handler_b);
606+ control.call_lifecycle_event_handler(mir_lifecycle_state_resumed);
607+
608+ EXPECT_TRUE(a_called);
609+ EXPECT_FALSE(b_called);
610+}
611+
612+TEST(LifeCycleControl, UpdateHandlesDifferingTypes)
613+{
614+ mir::client::LifecycleControl control;
615+
616+ a_called = false;
617+ b_called = false;
618+ auto non_fn_pointer_handler = [](MirLifecycleState){};
619+
620+ control.set_lifecycle_event_handler(non_fn_pointer_handler);
621+ control.replace_lifecycle_event_handler_if_matches(&handler_a, &handler_b);
622+ control.call_lifecycle_event_handler(mir_lifecycle_state_resumed);
623+
624+ EXPECT_FALSE(a_called);
625+ EXPECT_FALSE(b_called);
626+}

Subscribers

People subscribed via source and target branches