Mir

Merge lp:~alan-griffiths/mir/fix-1593655 into lp:mir

Proposed by Alan Griffiths
Status: Merged
Merged at revision: 3588
Proposed branch: lp:~alan-griffiths/mir/fix-1593655
Merge into: lp:mir
Diff against target: 250 lines (+112/-2)
9 files modified
include/server/mir/server.h (+4/-0)
src/include/server/mir/default_server_configuration.h (+1/-0)
src/include/server/mir/server_configuration.h (+3/-1)
src/server/default_server_configuration.cpp (+5/-0)
src/server/display_server.cpp (+5/-1)
src/server/server.cpp (+22/-0)
src/server/symbols.map (+8/-0)
tests/acceptance-tests/CMakeLists.txt (+1/-0)
tests/acceptance-tests/server_stop_callback.cpp (+63/-0)
To merge this branch: bzr merge lp:~alan-griffiths/mir/fix-1593655
Reviewer Review Type Date Requested Status
Mir CI Bot continuous-integration Needs Fixing
Chris Halse Rogers Approve
Kevin DuBois (community) Approve
Review via email: mp+299533@code.launchpad.net

Commit message

Add callback option to notify that the server is about to stop

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

PASSED: Continuous integration, rev:3586
https://mir-jenkins.ubuntu.com/job/mir-ci/1256/
Executed test runs:
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-mir/1465
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-0-fetch/1517
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-1-sourcepkg/release=vivid+overlay/1508
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-1-sourcepkg/release=xenial/1508
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=clang,platform=mesa,release=vivid+overlay/1479
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=clang,platform=mesa,release=vivid+overlay/1479/artifact/output/*zip*/output.zip
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=gcc,platform=mesa,release=xenial/1479
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=gcc,platform=mesa,release=xenial/1479/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/1479
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=cross-armhf,compiler=gcc,platform=android,release=vivid+overlay/1479/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/1479
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=i386,compiler=gcc,platform=android,release=vivid+overlay/1479/artifact/output/*zip*/output.zip
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=i386,compiler=gcc,platform=mesa,release=xenial/1479
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=i386,compiler=gcc,platform=mesa,release=xenial/1479/artifact/output/*zip*/output.zip

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

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

lgtm

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

LGTM

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

FAILED: Autolanding.
More details in the following jenkins job:
https://mir-jenkins.ubuntu.com/job/mir-autolanding/391/
Executed test runs:
    FAILURE: https://mir-jenkins.ubuntu.com/job/build-mir/1478/console
    None: https://mir-jenkins.ubuntu.com/job/generic-land-mp/419/console
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-0-fetch/1530
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-1-sourcepkg/release=vivid+overlay/1521
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-1-sourcepkg/release=xenial+overlay/1521
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-1-sourcepkg/release=yakkety/1521
    FAILURE: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=clang,platform=mesa,release=vivid+overlay/1493/console
    FAILURE: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=gcc,platform=mesa,release=xenial+overlay/1493/console
    FAILURE: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=cross-armhf,compiler=gcc,platform=android,release=vivid+overlay/1493/console
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=cross-armhf,compiler=gcc,platform=android,release=vivid+overlay/1493/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/1493
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=i386,compiler=gcc,platform=android,release=vivid+overlay/1493/artifact/output/*zip*/output.zip
    FAILURE: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=i386,compiler=gcc,platform=mesa,release=xenial+overlay/1493/console

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

https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=clang,platform=mesa,release=vivid+overlay/1493/consoleFull

09:10:14 15: [ FAILED ] Process.a_main_fn_is_executed
09:10:14 15: [ FAILED ] Process.a_successful_exit_function_succeeds

https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=i386,compiler=gcc,platform=mesa,release=xenial+overlay/1493/consoleFull

09:06:54 17: [ FAILED ] Process.a_main_fn_is_executed
09:06:54 17: [ FAILED ] Process.a_successful_exit_function_succeeds

These are unrelated and odd (as this is a fundamental part of the test framework and if wrong should cause numerous failures). I can only imagine the build agent got no CPU for so long that wait_for_termination() timed out.

logged as lp:1602199

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

FAILED: Autolanding.
More details in the following jenkins job:
https://mir-jenkins.ubuntu.com/job/mir-autolanding/392/
Executed test runs:
    FAILURE: https://mir-jenkins.ubuntu.com/job/build-mir/1479/console
    None: https://mir-jenkins.ubuntu.com/job/generic-land-mp/420/console
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-0-fetch/1531
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-1-sourcepkg/release=vivid+overlay/1522
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-1-sourcepkg/release=xenial+overlay/1522
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-1-sourcepkg/release=yakkety/1522
    FAILURE: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=clang,platform=mesa,release=vivid+overlay/1494/console
    FAILURE: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=gcc,platform=mesa,release=xenial+overlay/1494/console
    FAILURE: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=cross-armhf,compiler=gcc,platform=android,release=vivid+overlay/1494/console
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=i386,compiler=gcc,platform=android,release=vivid+overlay/1494
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=i386,compiler=gcc,platform=android,release=vivid+overlay/1494/artifact/output/*zip*/output.zip
    FAILURE: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=i386,compiler=gcc,platform=mesa,release=xenial+overlay/1494/console

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

lp:1602199 again. (Which has also been seen on another branch.)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'include/server/mir/server.h'
2--- include/server/mir/server.h 2016-06-22 14:43:28 +0000
3+++ include/server/mir/server.h 2016-07-08 12:01:51 +0000
4@@ -194,6 +194,10 @@
5 /// If multiple callbacks are added they will be invoked in the sequence added.
6 void add_init_callback(std::function<void()> const& init_callback);
7
8+ /// Add a callback to be invoked when the server is about to stop,
9+ /// If multiple callbacks are added they will be invoked in the reverse sequence added.
10+ void add_stop_callback(std::function<void()> const& stop_callback);
11+
12 /// Set a handler for exceptions. This is invoked in a catch (...) block and
13 /// the exception can be re-thrown to retrieve type information.
14 /// The default action is to call mir::report_exception(std::cerr)
15
16=== modified file 'src/include/server/mir/default_server_configuration.h'
17--- src/include/server/mir/default_server_configuration.h 2016-06-24 07:11:40 +0000
18+++ src/include/server/mir/default_server_configuration.h 2016-07-08 12:01:51 +0000
19@@ -177,6 +177,7 @@
20 std::shared_ptr<input::InputDispatcher> the_input_dispatcher() override;
21 std::shared_ptr<EmergencyCleanup> the_emergency_cleanup() override;
22 std::shared_ptr<cookie::Authority> the_cookie_authority() override;
23+ std::function<void()> the_stop_callback() override;
24 /**
25 * Function to call when a "fatal" error occurs. This implementation allows
26 * the default strategy to be overridden by --on-fatal-error-except to avoid a
27
28=== modified file 'src/include/server/mir/server_configuration.h'
29--- src/include/server/mir/server_configuration.h 2016-01-29 08:18:22 +0000
30+++ src/include/server/mir/server_configuration.h 2016-07-08 12:01:51 +0000
31@@ -1,5 +1,5 @@
32 /*
33- * Copyright © 2012 Canonical Ltd.
34+ * Copyright © 2012, 2016 Canonical Ltd.
35 *
36 * This program is free software: you can redistribute it and/or modify it
37 * under the terms of the GNU General Public License version 3,
38@@ -18,6 +18,7 @@
39 #ifndef MIR_SERVER_CONFIGURATION_H_
40 #define MIR_SERVER_CONFIGURATION_H_
41
42+#include <functional>
43 #include <memory>
44
45 namespace mir
46@@ -82,6 +83,7 @@
47 virtual std::shared_ptr<cookie::Authority> the_cookie_authority() = 0;
48 virtual auto the_fatal_error_strategy() -> void (*)(char const* reason, ...) = 0;
49 virtual std::shared_ptr<scene::ApplicationNotRespondingDetector> the_application_not_responding_detector() = 0;
50+ virtual std::function<void()> the_stop_callback() = 0;
51
52 protected:
53 ServerConfiguration() = default;
54
55=== modified file 'src/server/default_server_configuration.cpp'
56--- src/server/default_server_configuration.cpp 2016-06-02 05:33:50 +0000
57+++ src/server/default_server_configuration.cpp 2016-07-08 12:01:51 +0000
58@@ -193,6 +193,11 @@
59 });
60 }
61
62+std::function<void()> mir::DefaultServerConfiguration::the_stop_callback()
63+{
64+ return []{};
65+}
66+
67 auto mir::DefaultServerConfiguration::the_fatal_error_strategy()
68 -> void (*)(char const* reason, ...)
69 {
70
71=== modified file 'src/server/display_server.cpp'
72--- src/server/display_server.cpp 2016-05-03 06:55:25 +0000
73+++ src/server/display_server.cpp 2016-07-08 12:01:51 +0000
74@@ -54,7 +54,8 @@
75 input_manager{config.the_input_manager()},
76 main_loop{config.the_main_loop()},
77 server_status_listener{config.the_server_status_listener()},
78- display_changer{config.the_display_changer()}
79+ display_changer{config.the_display_changer()},
80+ stop_callback{config.the_stop_callback()}
81 {
82 display->register_configuration_change_handler(
83 *main_loop,
84@@ -180,6 +181,8 @@
85 std::shared_ptr<mir::MainLoop> const main_loop;
86 std::shared_ptr<mir::ServerStatusListener> const server_status_listener;
87 std::shared_ptr<mir::DisplayChanger> const display_changer;
88+ std::function<void()> const stop_callback;
89+
90 };
91
92 mir::DisplayServer::DisplayServer(ServerConfiguration& config) :
93@@ -222,5 +225,6 @@
94
95 void mir::DisplayServer::stop()
96 {
97+ p.load()->stop_callback();
98 p.load()->main_loop->stop();
99 }
100
101=== modified file 'src/server/server.cpp'
102--- src/server/server.cpp 2016-07-05 08:19:55 +0000
103+++ src/server/server.cpp 2016-07-08 12:01:51 +0000
104@@ -148,6 +148,7 @@
105 std::shared_ptr<ServerConfiguration> server_config;
106
107 std::function<void()> init_callback{[]{}};
108+ std::function<void()> stop_callback{[]{}};
109 int argc{0};
110 char const** argv{nullptr};
111 std::function<void()> exception_handler{};
112@@ -270,6 +271,11 @@
113 return mir::DefaultServerConfiguration::the_renderer_factory();
114 }
115
116+ std::function<void()> the_stop_callback() override
117+ {
118+ return self->stop_callback;
119+ }
120+
121 using mir::DefaultServerConfiguration::the_options;
122
123 FOREACH_OVERRIDE(MIR_SERVER_CONFIG_OVERRIDE)
124@@ -353,6 +359,19 @@
125 self->init_callback = updated;
126 }
127
128+void mir::Server::add_stop_callback(std::function<void()> const& stop_callback)
129+{
130+ auto const& existing = self->stop_callback;
131+
132+ auto const updated = [=]
133+ {
134+ stop_callback();
135+ existing();
136+ };
137+
138+ self->stop_callback = updated;
139+}
140+
141 void mir::Server::set_command_line_handler(
142 std::function<void(int argc, char const* const* argv)> const& command_line_hander)
143 {
144@@ -464,7 +483,10 @@
145 mir::log_info("Stopping");
146 if (self->server_config)
147 if (auto const main_loop = the_main_loop())
148+ {
149+ self->stop_callback();
150 main_loop->stop();
151+ }
152 }
153
154 bool mir::Server::exited_normally()
155
156=== modified file 'src/server/symbols.map'
157--- src/server/symbols.map 2016-06-24 07:11:40 +0000
158+++ src/server/symbols.map 2016-07-08 12:01:51 +0000
159@@ -840,3 +840,11 @@
160 VTT?for?mir::scene::ApplicationNotRespondingDetectorWrapper;
161 };
162 } MIR_SERVER_0.22;
163+
164+MIR_SERVER_0.25 {
165+ global:
166+ extern "C++" {
167+ mir::DefaultServerConfiguration::the_stop_callback*;
168+ mir::Server::add_stop_callback*;
169+ };
170+} MIR_SERVER_0.24;
171
172=== modified file 'tests/acceptance-tests/CMakeLists.txt'
173--- tests/acceptance-tests/CMakeLists.txt 2016-06-27 15:03:55 +0000
174+++ tests/acceptance-tests/CMakeLists.txt 2016-07-08 12:01:51 +0000
175@@ -10,6 +10,7 @@
176 server_configuration_wrapping.cpp
177 server_configuration_options.cpp
178 server_signal_handling.cpp
179+ server_stop_callback.cpp
180 test_application_not_responding_detection.cpp
181 test_client_header_version.cpp
182 test_client_input.cpp
183
184=== added file 'tests/acceptance-tests/server_stop_callback.cpp'
185--- tests/acceptance-tests/server_stop_callback.cpp 1970-01-01 00:00:00 +0000
186+++ tests/acceptance-tests/server_stop_callback.cpp 2016-07-08 12:01:51 +0000
187@@ -0,0 +1,63 @@
188+/*
189+ * Copyright © 2016 Canonical Ltd.
190+ *
191+ * This program is free software: you can redistribute it and/or modify it
192+ * under the terms of the GNU General Public License version 3,
193+ * as published by the Free Software Foundation.
194+ *
195+ * This program is distributed in the hope that it will be useful,
196+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
197+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
198+ * GNU General Public License for more details.
199+ *
200+ * You should have received a copy of the GNU General Public License
201+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
202+ *
203+ * Authored by: Alan Griffiths <alan@octopull.co.uk>
204+ */
205+
206+#include "mir_test_framework/headless_test.h"
207+
208+#include <gtest/gtest.h>
209+#include <gmock/gmock.h>
210+
211+namespace mt = mir::test;
212+namespace mtf = mir_test_framework;
213+
214+namespace
215+{
216+struct ServerStopCallback : mtf::HeadlessTest
217+{
218+ ServerStopCallback() { add_to_environment("MIR_SERVER_NO_FILE", ""); }
219+
220+ MOCK_CONST_METHOD0(stop_callback0, void());
221+ MOCK_CONST_METHOD0(stop_callback1, void());
222+ MOCK_CONST_METHOD0(stop_callback2, void());
223+};
224+}
225+
226+TEST_F(ServerStopCallback, is_invoked)
227+{
228+ server.add_stop_callback([this]{ stop_callback0(); });
229+
230+ start_server();
231+
232+ EXPECT_CALL(*this, stop_callback0());
233+ stop_server();
234+}
235+
236+TEST_F(ServerStopCallback, invoked_in_reverse_order)
237+{
238+ server.add_stop_callback([this]{ stop_callback0(); });
239+ server.add_stop_callback([this]{ stop_callback1(); });
240+ server.add_stop_callback([this]{ stop_callback2(); });
241+
242+ start_server();
243+
244+ testing::InSequence seq;
245+ EXPECT_CALL(*this, stop_callback2());
246+ EXPECT_CALL(*this, stop_callback1());
247+ EXPECT_CALL(*this, stop_callback0());
248+
249+ stop_server();
250+}

Subscribers

People subscribed via source and target branches