Merge lp:~alan-griffiths/mir/another-acceptance-test-uses-mir-Server-API into lp:mir
- another-acceptance-test-uses-mir-Server-API
- Merge into development-branch
Proposed by
Alan Griffiths
Status: | Work in progress |
---|---|
Proposed branch: | lp:~alan-griffiths/mir/another-acceptance-test-uses-mir-Server-API |
Merge into: | lp:mir |
Prerequisite: | lp:~alan-griffiths/mir/some-acceptance-tests-use-mir-Server-API |
Diff against target: |
583 lines (+219/-121) 11 files modified
include/server/mir/server.h (+9/-0) server-ABI-sha1sums (+1/-1) src/server/server.cpp (+9/-0) src/server/symbols.map (+2/-0) tests/acceptance-tests/test_client_library.cpp (+2/-21) tests/acceptance-tests/test_prompt_session_client_api.cpp (+114/-98) tests/include/mir_test_framework/headless_in_process_server.h (+36/-0) tests/include/mir_test_framework/headless_test.h (+3/-0) tests/mir_test_framework/CMakeLists.txt (+1/-0) tests/mir_test_framework/headless_in_process_server.cpp (+36/-0) tests/mir_test_framework/headless_test.cpp (+6/-1) |
To merge this branch: | bzr merge lp:~alan-griffiths/mir/another-acceptance-test-uses-mir-Server-API |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Mir development team | Pending | ||
Review via email: mp+239581@code.launchpad.net |
Commit message
test: Move another of the acceptance test suites [PromptSessionC
Description of the change
test: Move another of the acceptance test suites [PromptSessionC
It cleans up the "HeadlessInProc
To post a comment you must log in.
- 2003. By Alan Griffiths
-
merge lp:~alan-griffiths/mir/some-acceptance-tests-use-mir-Server-API
- 2004. By Alan Griffiths
-
Revert accidental deletions in debian
- 2005. By Alan Griffiths
-
Delete debug code
- 2006. By Alan Griffiths
-
Reduce diff
- 2007. By Alan Griffiths
-
merge lp:~alan-griffiths/mir/some-acceptance-tests-use-mir-Server-API
Unmerged revisions
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 2014-10-24 18:38:24 +0000 | |||
3 | +++ include/server/mir/server.h 2014-10-24 18:38:25 +0000 | |||
4 | @@ -35,6 +35,7 @@ | |||
5 | 35 | class PlacementStrategy; | 35 | class PlacementStrategy; |
6 | 36 | class SessionListener; | 36 | class SessionListener; |
7 | 37 | class PromptSessionListener; | 37 | class PromptSessionListener; |
8 | 38 | class PromptSessionManager; | ||
9 | 38 | class SurfaceConfigurator; | 39 | class SurfaceConfigurator; |
10 | 39 | class SessionCoordinator; | 40 | class SessionCoordinator; |
11 | 40 | class SurfaceCoordinator; | 41 | class SurfaceCoordinator; |
12 | @@ -211,6 +212,9 @@ | |||
13 | 211 | /// \return the prompt session listener. | 212 | /// \return the prompt session listener. |
14 | 212 | auto the_prompt_session_listener() const -> std::shared_ptr<scene::PromptSessionListener>; | 213 | auto the_prompt_session_listener() const -> std::shared_ptr<scene::PromptSessionListener>; |
15 | 213 | 214 | ||
16 | 215 | /// \return the prompt session manager. | ||
17 | 216 | auto the_prompt_session_manager() const ->std::shared_ptr<scene::PromptSessionManager>; | ||
18 | 217 | |||
19 | 214 | /// \return the session authorizer. | 218 | /// \return the session authorizer. |
20 | 215 | auto the_session_authorizer() const -> std::shared_ptr<frontend::SessionAuthorizer>; | 219 | auto the_session_authorizer() const -> std::shared_ptr<frontend::SessionAuthorizer>; |
21 | 216 | 220 | ||
22 | @@ -247,6 +251,11 @@ | |||
23 | 247 | /// using the format "fd://%d". | 251 | /// using the format "fd://%d". |
24 | 248 | /// \param connect_handler callback to be invoked when the client connects | 252 | /// \param connect_handler callback to be invoked when the client connects |
25 | 249 | auto open_client_socket(ConnectHandler const& connect_handler) -> int; | 253 | auto open_client_socket(ConnectHandler const& connect_handler) -> int; |
26 | 254 | |||
27 | 255 | /// Get a file descriptor that can be used to connect a prompt provider | ||
28 | 256 | /// It can be passed to another process, or used directly with mir_connect() | ||
29 | 257 | /// using the format "fd://%d". | ||
30 | 258 | auto open_prompt_socket() -> int; | ||
31 | 250 | /** @} */ | 259 | /** @} */ |
32 | 251 | private: | 260 | private: |
33 | 252 | void apply_settings() const; | 261 | void apply_settings() const; |
34 | 253 | 262 | ||
35 | === modified file 'server-ABI-sha1sums' | |||
36 | --- server-ABI-sha1sums 2014-10-24 18:38:24 +0000 | |||
37 | +++ server-ABI-sha1sums 2014-10-24 18:38:25 +0000 | |||
38 | @@ -95,7 +95,7 @@ | |||
39 | 95 | 993e9f458ffc4288d304413f3fa0b1dcc95a093d include/server/mir/scene/surface_observer.h | 95 | 993e9f458ffc4288d304413f3fa0b1dcc95a093d include/server/mir/scene/surface_observer.h |
40 | 96 | 7ef3e99901168cda296d74d05a979f47bf9c3ff1 include/server/mir/server_action_queue.h | 96 | 7ef3e99901168cda296d74d05a979f47bf9c3ff1 include/server/mir/server_action_queue.h |
41 | 97 | 8d83a51c278b8b71866d2178d9b6387c1f91a7d0 include/server/mir/server_configuration.h | 97 | 8d83a51c278b8b71866d2178d9b6387c1f91a7d0 include/server/mir/server_configuration.h |
43 | 98 | 2ead070cf169e59015edfd94ca84295ac5adcdd6 include/server/mir/server.h | 98 | 54faba134ab52958228db3ccc19d45aff7068ca6 include/server/mir/server.h |
44 | 99 | 86098b500339bfccd07a9bed8298f75a68b18f5c include/server/mir/server_status_listener.h | 99 | 86098b500339bfccd07a9bed8298f75a68b18f5c include/server/mir/server_status_listener.h |
45 | 100 | 860c04f32b60e680140148dc9dc2295de145b9c1 include/server/mir/shell/display_layout.h | 100 | 860c04f32b60e680140148dc9dc2295de145b9c1 include/server/mir/shell/display_layout.h |
46 | 101 | 6a2107b01feae13060d5c305804906e53c52e0be include/server/mir/shell/focus_controller.h | 101 | 6a2107b01feae13060d5c305804906e53c52e0be include/server/mir/shell/focus_controller.h |
47 | 102 | 102 | ||
48 | === modified file 'src/server/server.cpp' | |||
49 | --- src/server/server.cpp 2014-10-24 18:38:24 +0000 | |||
50 | +++ src/server/server.cpp 2014-10-24 18:38:25 +0000 | |||
51 | @@ -61,6 +61,7 @@ | |||
52 | 61 | MACRO(the_session_authorizer)\ | 61 | MACRO(the_session_authorizer)\ |
53 | 62 | MACRO(the_session_coordinator)\ | 62 | MACRO(the_session_coordinator)\ |
54 | 63 | MACRO(the_session_listener)\ | 63 | MACRO(the_session_listener)\ |
55 | 64 | MACRO(the_prompt_session_manager)\ | ||
56 | 64 | MACRO(the_shell_display_layout)\ | 65 | MACRO(the_shell_display_layout)\ |
57 | 65 | MACRO(the_surface_configurator)\ | 66 | MACRO(the_surface_configurator)\ |
58 | 66 | MACRO(the_surface_coordinator) | 67 | MACRO(the_surface_coordinator) |
59 | @@ -310,6 +311,14 @@ | |||
60 | 310 | BOOST_THROW_EXCEPTION(std::logic_error("Cannot open connection when not running")); | 311 | BOOST_THROW_EXCEPTION(std::logic_error("Cannot open connection when not running")); |
61 | 311 | } | 312 | } |
62 | 312 | 313 | ||
63 | 314 | auto mir::Server::open_prompt_socket() -> int | ||
64 | 315 | { | ||
65 | 316 | if (auto const config = self->server_config) | ||
66 | 317 | return config->the_prompt_connector()->client_socket_fd(); | ||
67 | 318 | |||
68 | 319 | BOOST_THROW_EXCEPTION(std::logic_error("Cannot open connection when not running")); | ||
69 | 320 | } | ||
70 | 321 | |||
71 | 313 | auto mir::Server::open_client_socket(ConnectHandler const& connect_handler) -> int | 322 | auto mir::Server::open_client_socket(ConnectHandler const& connect_handler) -> int |
72 | 314 | { | 323 | { |
73 | 315 | if (auto const config = self->server_config) | 324 | if (auto const config = self->server_config) |
74 | 316 | 325 | ||
75 | === modified file 'src/server/symbols.map' | |||
76 | --- src/server/symbols.map 2014-10-24 18:38:24 +0000 | |||
77 | +++ src/server/symbols.map 2014-10-24 18:38:25 +0000 | |||
78 | @@ -394,6 +394,7 @@ | |||
79 | 394 | mir::Server::exited_normally*; | 394 | mir::Server::exited_normally*; |
80 | 395 | mir::Server::get_options*; | 395 | mir::Server::get_options*; |
81 | 396 | mir::Server::open_client_socket*; | 396 | mir::Server::open_client_socket*; |
82 | 397 | mir::Server::open_prompt_socket*; | ||
83 | 397 | mir::Server::override_the_compositor*; | 398 | mir::Server::override_the_compositor*; |
84 | 398 | mir::Server::override_the_cursor_listener*; | 399 | mir::Server::override_the_cursor_listener*; |
85 | 399 | mir::Server::override_the_gl_config*; | 400 | mir::Server::override_the_gl_config*; |
86 | @@ -423,6 +424,7 @@ | |||
87 | 423 | mir::Server::the_graphics_platform*; | 424 | mir::Server::the_graphics_platform*; |
88 | 424 | mir::Server::the_main_loop*; | 425 | mir::Server::the_main_loop*; |
89 | 425 | mir::Server::the_prompt_session_listener*; | 426 | mir::Server::the_prompt_session_listener*; |
90 | 427 | mir::Server::the_prompt_session_manager*; | ||
91 | 426 | mir::Server::the_session_authorizer*; | 428 | mir::Server::the_session_authorizer*; |
92 | 427 | mir::Server::the_session_coordinator*; | 429 | mir::Server::the_session_coordinator*; |
93 | 428 | mir::Server::the_session_listener*; | 430 | mir::Server::the_session_listener*; |
94 | 429 | 431 | ||
95 | === modified file 'tests/acceptance-tests/test_client_library.cpp' | |||
96 | --- tests/acceptance-tests/test_client_library.cpp 2014-10-24 18:38:24 +0000 | |||
97 | +++ tests/acceptance-tests/test_client_library.cpp 2014-10-24 18:38:25 +0000 | |||
98 | @@ -19,7 +19,7 @@ | |||
99 | 19 | #include "mir_toolkit/mir_client_library.h" | 19 | #include "mir_toolkit/mir_client_library.h" |
100 | 20 | #include "mir_toolkit/mir_client_library_debug.h" | 20 | #include "mir_toolkit/mir_client_library_debug.h" |
101 | 21 | 21 | ||
103 | 22 | #include "mir_test_framework/headless_test.h" | 22 | #include "mir_test_framework/headless_in_process_server.h" |
104 | 23 | #include "mir_test_framework/using_stub_client_platform.h" | 23 | #include "mir_test_framework/using_stub_client_platform.h" |
105 | 24 | 24 | ||
106 | 25 | #include "src/client/client_buffer.h" | 25 | #include "src/client/client_buffer.h" |
107 | @@ -50,28 +50,9 @@ | |||
108 | 50 | namespace mc = mir::compositor; | 50 | namespace mc = mir::compositor; |
109 | 51 | namespace mcl = mir::client; | 51 | namespace mcl = mir::client; |
110 | 52 | namespace mtf = mir_test_framework; | 52 | namespace mtf = mir_test_framework; |
111 | 53 | |||
112 | 54 | namespace | 53 | namespace |
113 | 55 | { | 54 | { |
133 | 56 | struct HeadlessInProcessServer : mir_test_framework::HeadlessTest | 55 | struct ClientLibrary : mtf::HeadlessInProcessServer |
115 | 57 | { | ||
116 | 58 | HeadlessInProcessServer() | ||
117 | 59 | { | ||
118 | 60 | add_to_environment("MIR_SERVER_NO_FILE", ""); | ||
119 | 61 | } | ||
120 | 62 | |||
121 | 63 | void SetUp() override | ||
122 | 64 | { | ||
123 | 65 | start_server(); | ||
124 | 66 | } | ||
125 | 67 | |||
126 | 68 | void TearDown() override | ||
127 | 69 | { | ||
128 | 70 | stop_server(); | ||
129 | 71 | } | ||
130 | 72 | }; | ||
131 | 73 | |||
132 | 74 | struct ClientLibrary : HeadlessInProcessServer | ||
134 | 75 | { | 56 | { |
135 | 76 | mtf::UsingStubClientPlatform using_stub_client_platform; | 57 | mtf::UsingStubClientPlatform using_stub_client_platform; |
136 | 77 | 58 | ||
137 | 78 | 59 | ||
138 | === modified file 'tests/acceptance-tests/test_prompt_session_client_api.cpp' | |||
139 | --- tests/acceptance-tests/test_prompt_session_client_api.cpp 2014-10-21 16:21:14 +0000 | |||
140 | +++ tests/acceptance-tests/test_prompt_session_client_api.cpp 2014-10-24 18:38:25 +0000 | |||
141 | @@ -21,13 +21,14 @@ | |||
142 | 21 | #include "mir/scene/prompt_session.h" | 21 | #include "mir/scene/prompt_session.h" |
143 | 22 | #include "mir/scene/prompt_session_manager.h" | 22 | #include "mir/scene/prompt_session_manager.h" |
144 | 23 | #include "mir/scene/session.h" | 23 | #include "mir/scene/session.h" |
145 | 24 | #include "mir/shell/session_coordinator_wrapper.h" | ||
146 | 24 | #include "mir/frontend/session_credentials.h" | 25 | #include "mir/frontend/session_credentials.h" |
147 | 25 | #include "mir/frontend/shell.h" | 26 | #include "mir/frontend/shell.h" |
148 | 27 | #include "mir/cached_ptr.h" | ||
149 | 26 | #include "mir/fd.h" | 28 | #include "mir/fd.h" |
150 | 27 | 29 | ||
151 | 28 | #include "mir_test_doubles/stub_session_authorizer.h" | 30 | #include "mir_test_doubles/stub_session_authorizer.h" |
154 | 29 | #include "mir_test_framework/stubbed_server_configuration.h" | 31 | #include "mir_test_framework/headless_in_process_server.h" |
153 | 30 | #include "mir_test_framework/in_process_server.h" | ||
155 | 31 | #include "mir_test_framework/using_stub_client_platform.h" | 32 | #include "mir_test_framework/using_stub_client_platform.h" |
156 | 32 | #include "mir_test/popen.h" | 33 | #include "mir_test/popen.h" |
157 | 33 | 34 | ||
158 | @@ -40,6 +41,7 @@ | |||
159 | 40 | namespace mtd = mir::test::doubles; | 41 | namespace mtd = mir::test::doubles; |
160 | 41 | namespace mtf = mir_test_framework; | 42 | namespace mtf = mir_test_framework; |
161 | 42 | namespace ms = mir::scene; | 43 | namespace ms = mir::scene; |
162 | 44 | namespace msh = mir::shell; | ||
163 | 43 | namespace mf = mir::frontend; | 45 | namespace mf = mir::frontend; |
164 | 44 | 46 | ||
165 | 45 | using namespace testing; | 47 | using namespace testing; |
166 | @@ -48,20 +50,8 @@ | |||
167 | 48 | { | 50 | { |
168 | 49 | struct MockPromptSessionListener : ms::PromptSessionListener | 51 | struct MockPromptSessionListener : ms::PromptSessionListener |
169 | 50 | { | 52 | { |
172 | 51 | MockPromptSessionListener(std::shared_ptr<ms::PromptSessionListener> const& wrapped) : | 53 | MockPromptSessionListener() |
171 | 52 | wrapped(wrapped) | ||
173 | 53 | { | 54 | { |
174 | 54 | ON_CALL(*this, starting(_)).WillByDefault(Invoke( | ||
175 | 55 | wrapped.get(), &ms::PromptSessionListener::starting)); | ||
176 | 56 | |||
177 | 57 | ON_CALL(*this, stopping(_)).WillByDefault(Invoke( | ||
178 | 58 | wrapped.get(), &ms::PromptSessionListener::stopping)); | ||
179 | 59 | |||
180 | 60 | ON_CALL(*this, prompt_provider_added(_, _)).WillByDefault(Invoke( | ||
181 | 61 | wrapped.get(), &ms::PromptSessionListener::prompt_provider_added)); | ||
182 | 62 | |||
183 | 63 | ON_CALL(*this, prompt_provider_removed(_, _)).WillByDefault(Invoke( | ||
184 | 64 | wrapped.get(), &ms::PromptSessionListener::prompt_provider_removed)); | ||
185 | 65 | } | 55 | } |
186 | 66 | 56 | ||
187 | 67 | MOCK_METHOD1(starting, void(std::shared_ptr<ms::PromptSession> const& prompt_session)); | 57 | MOCK_METHOD1(starting, void(std::shared_ptr<ms::PromptSession> const& prompt_session)); |
188 | @@ -72,8 +62,6 @@ | |||
189 | 72 | 62 | ||
190 | 73 | MOCK_METHOD2(prompt_provider_removed, | 63 | MOCK_METHOD2(prompt_provider_removed, |
191 | 74 | void(ms::PromptSession const& session, std::shared_ptr<ms::Session> const& provider)); | 64 | void(ms::PromptSession const& session, std::shared_ptr<ms::Session> const& provider)); |
192 | 75 | |||
193 | 76 | std::shared_ptr<ms::PromptSessionListener> const wrapped; | ||
194 | 77 | }; | 65 | }; |
195 | 78 | 66 | ||
196 | 79 | struct MockSessionAuthorizer : public mtd::StubSessionAuthorizer | 67 | struct MockSessionAuthorizer : public mtd::StubSessionAuthorizer |
197 | @@ -88,110 +76,136 @@ | |||
198 | 88 | MOCK_METHOD1(prompt_session_is_allowed, bool(mf::SessionCredentials const&)); | 76 | MOCK_METHOD1(prompt_session_is_allowed, bool(mf::SessionCredentials const&)); |
199 | 89 | }; | 77 | }; |
200 | 90 | 78 | ||
202 | 91 | struct PromptSessionTestConfiguration : mtf::StubbedServerConfiguration | 79 | // We need to fake the client_pid for the as that is used to identify sessions |
203 | 80 | class HookSessionCoordinator : public msh::SessionCoordinatorWrapper | ||
204 | 92 | { | 81 | { |
242 | 93 | std::shared_ptr<ms::PromptSessionListener> the_prompt_session_listener() override | 82 | public: |
243 | 94 | { | 83 | HookSessionCoordinator( |
244 | 95 | return prompt_session_listener([this]() | 84 | std::shared_ptr<ms::SessionCoordinator> const& wrapped, |
245 | 96 | ->std::shared_ptr<ms::PromptSessionListener> | 85 | std::vector<pid_t> const& pids) : |
246 | 97 | { | 86 | msh::SessionCoordinatorWrapper(wrapped), |
247 | 98 | return the_mock_prompt_session_listener(); | 87 | pids(pids) |
248 | 99 | }); | 88 | { |
249 | 100 | } | 89 | } |
250 | 101 | 90 | ||
251 | 102 | std::shared_ptr<MockPromptSessionListener> the_mock_prompt_session_listener() | 91 | auto open_session( |
252 | 103 | { | 92 | pid_t client_pid, |
253 | 104 | return mock_prompt_session_listener([this] | 93 | std::string const& name, |
254 | 105 | { | 94 | std::shared_ptr<mf::EventSink> const& sink) |
255 | 106 | return std::make_shared<NiceMock<MockPromptSessionListener>>( | 95 | -> std::shared_ptr<mf::Session> override |
256 | 107 | mtf::StubbedServerConfiguration::the_prompt_session_listener()); | 96 | { |
257 | 108 | }); | 97 | auto const override_pid = (next != pids.end()) ? *next++ : client_pid; |
258 | 109 | } | 98 | |
259 | 110 | 99 | return wrapped->open_session(override_pid, name, sink); | |
260 | 111 | std::shared_ptr<mf::SessionAuthorizer> the_session_authorizer() override | 100 | } |
261 | 112 | { | 101 | |
262 | 113 | return session_authorizer([this]() | 102 | private: |
263 | 114 | ->std::shared_ptr<mf::SessionAuthorizer> | 103 | std::vector<pid_t> const pids; |
264 | 115 | { | 104 | std::vector<pid_t>::const_iterator next{pids.begin()}; |
228 | 116 | return the_mock_session_authorizer(); | ||
229 | 117 | }); | ||
230 | 118 | } | ||
231 | 119 | |||
232 | 120 | std::shared_ptr<MockSessionAuthorizer> the_mock_session_authorizer() | ||
233 | 121 | { | ||
234 | 122 | return mock_prompt_session_authorizer([this] | ||
235 | 123 | { | ||
236 | 124 | return std::make_shared<NiceMock<MockSessionAuthorizer>>(); | ||
237 | 125 | }); | ||
238 | 126 | } | ||
239 | 127 | |||
240 | 128 | mir::CachedPtr<MockPromptSessionListener> mock_prompt_session_listener; | ||
241 | 129 | mir::CachedPtr<MockSessionAuthorizer> mock_prompt_session_authorizer; | ||
265 | 130 | }; | 105 | }; |
266 | 131 | 106 | ||
268 | 132 | struct PromptSessionClientAPI : mtf::InProcessServer | 107 | struct PromptSessionClientAPI : mtf::HeadlessInProcessServer |
269 | 133 | { | 108 | { |
270 | 134 | PromptSessionTestConfiguration server_configuration; | ||
271 | 135 | |||
272 | 136 | mir::DefaultServerConfiguration& server_config() override | ||
273 | 137 | { return server_configuration; } | ||
274 | 138 | |||
275 | 139 | MirConnection* connection = nullptr; | 109 | MirConnection* connection = nullptr; |
276 | 140 | 110 | ||
277 | 141 | static constexpr pid_t application_session_pid = __LINE__; | 111 | static constexpr pid_t application_session_pid = __LINE__; |
278 | 142 | std::shared_ptr<mf::Session> application_session; | 112 | std::shared_ptr<mf::Session> application_session; |
279 | 113 | MirConnection* application_connection{nullptr}; | ||
280 | 143 | 114 | ||
281 | 144 | std::shared_ptr<ms::PromptSession> server_prompt_session; | 115 | std::shared_ptr<ms::PromptSession> server_prompt_session; |
282 | 145 | mtf::UsingStubClientPlatform using_stub_client_platform; | 116 | mtf::UsingStubClientPlatform using_stub_client_platform; |
283 | 146 | 117 | ||
284 | 118 | mir::CachedPtr<MockPromptSessionListener> mock_prompt_session_listener; | ||
285 | 119 | mir::CachedPtr<MockSessionAuthorizer> mock_prompt_session_authorizer; | ||
286 | 120 | |||
287 | 121 | std::shared_ptr<MockSessionAuthorizer> the_mock_session_authorizer() | ||
288 | 122 | { | ||
289 | 123 | return mock_prompt_session_authorizer([this] | ||
290 | 124 | { | ||
291 | 125 | return std::make_shared<NiceMock<MockSessionAuthorizer>>(); | ||
292 | 126 | }); | ||
293 | 127 | } | ||
294 | 128 | |||
295 | 129 | std::shared_ptr<MockPromptSessionListener> the_mock_prompt_session_listener() | ||
296 | 130 | { | ||
297 | 131 | return mock_prompt_session_listener([] | ||
298 | 132 | { | ||
299 | 133 | return std::make_shared<NiceMock<MockPromptSessionListener>>(); | ||
300 | 134 | }); | ||
301 | 135 | } | ||
302 | 136 | |||
303 | 137 | auto new_prompt_connection() -> std::string | ||
304 | 138 | { | ||
305 | 139 | auto const prompt_fd = server.open_prompt_socket(); | ||
306 | 140 | return HeadlessInProcessServer::connection(prompt_fd); | ||
307 | 141 | } | ||
308 | 142 | |||
309 | 143 | void start_application_session() | ||
310 | 144 | { | ||
311 | 145 | std::mutex application_session_mutex; | ||
312 | 146 | std::condition_variable application_session_cv; | ||
313 | 147 | |||
314 | 148 | auto connect_handler = [&](std::shared_ptr<mf::Session> const& session) | ||
315 | 149 | { | ||
316 | 150 | std::lock_guard<std::mutex> lock(application_session_mutex); | ||
317 | 151 | application_session = session; | ||
318 | 152 | application_session_cv.notify_one(); | ||
319 | 153 | }; | ||
320 | 154 | |||
321 | 155 | auto const fd = server.open_client_socket(connect_handler); | ||
322 | 156 | |||
323 | 157 | application_connection = mir_connect_sync(HeadlessInProcessServer::connection(fd).c_str(), __PRETTY_FUNCTION__); | ||
324 | 158 | |||
325 | 159 | std::unique_lock<std::mutex> lock(application_session_mutex); | ||
326 | 160 | application_session_cv.wait(lock, [&] { return !!application_session; }); | ||
327 | 161 | } | ||
328 | 162 | |||
329 | 147 | void SetUp() override | 163 | void SetUp() override |
330 | 148 | { | 164 | { |
338 | 149 | mtf::InProcessServer::SetUp(); | 165 | auto session_coordinator_wrapper = [&](std::shared_ptr<ms::SessionCoordinator> const& wrapped) |
339 | 150 | 166 | -> std::shared_ptr<ms::SessionCoordinator> | |
340 | 151 | std::shared_ptr<mf::EventSink> dummy_event_sink; | 167 | { |
341 | 152 | auto const the_frontend_shell = server_config().the_frontend_shell(); | 168 | std::vector<pid_t> fake_pids; |
342 | 153 | 169 | fake_pids.push_back(application_session_pid); | |
343 | 154 | application_session = the_frontend_shell->open_session( | 170 | |
344 | 155 | application_session_pid, __PRETTY_FUNCTION__, dummy_event_sink); | 171 | return std::make_shared<HookSessionCoordinator>(wrapped, fake_pids); |
345 | 172 | }; | ||
346 | 173 | |||
347 | 174 | server.override_the_session_authorizer([this]() | ||
348 | 175 | ->std::shared_ptr<mf::SessionAuthorizer> | ||
349 | 176 | { | ||
350 | 177 | return the_mock_session_authorizer(); | ||
351 | 178 | }); | ||
352 | 179 | |||
353 | 180 | server.override_the_prompt_session_listener([this] | ||
354 | 181 | { | ||
355 | 182 | return the_mock_prompt_session_listener(); | ||
356 | 183 | }); | ||
357 | 184 | |||
358 | 185 | server.wrap_session_coordinator(session_coordinator_wrapper); | ||
359 | 186 | |||
360 | 187 | mtf::HeadlessInProcessServer::SetUp(); | ||
361 | 188 | |||
362 | 189 | start_application_session(); | ||
363 | 156 | } | 190 | } |
364 | 157 | 191 | ||
365 | 158 | void capture_server_prompt_session() | 192 | void capture_server_prompt_session() |
366 | 159 | { | 193 | { |
367 | 160 | EXPECT_CALL(*the_mock_prompt_session_listener(), starting(_)). | 194 | EXPECT_CALL(*the_mock_prompt_session_listener(), starting(_)). |
373 | 161 | WillOnce(DoAll( | 195 | WillOnce(SaveArg<0>(&server_prompt_session)); |
369 | 162 | Invoke( | ||
370 | 163 | the_mock_prompt_session_listener()->wrapped.get(), | ||
371 | 164 | &ms::PromptSessionListener::starting), | ||
372 | 165 | SaveArg<0>(&server_prompt_session))); | ||
374 | 166 | } | 196 | } |
375 | 167 | 197 | ||
376 | 168 | void TearDown() override | 198 | void TearDown() override |
377 | 169 | { | 199 | { |
386 | 170 | // TODO It really shouldn't be necessary to close these sessions. | 200 | application_session.reset(); |
387 | 171 | // TODO But the MediatingDisplayChanger id destroyed without deregistering | 201 | if (application_connection) mir_connection_release(application_connection); |
380 | 172 | // TODO callbacks from the BroadcastingSessionEventSink which gets called in | ||
381 | 173 | // TODO SessionManager::~SessionManager() in code that the comments claim | ||
382 | 174 | // TODO works around broken ownership. | ||
383 | 175 | auto const the_frontend_shell = server_config().the_frontend_shell(); | ||
384 | 176 | the_frontend_shell->close_session(application_session); | ||
385 | 177 | |||
388 | 178 | if (connection) mir_connection_release(connection); | 202 | if (connection) mir_connection_release(connection); |
400 | 179 | mtf::InProcessServer::TearDown(); | 203 | mtf::HeadlessInProcessServer::TearDown(); |
390 | 180 | } | ||
391 | 181 | |||
392 | 182 | MockPromptSessionListener* the_mock_prompt_session_listener() | ||
393 | 183 | { | ||
394 | 184 | return server_configuration.the_mock_prompt_session_listener().get(); | ||
395 | 185 | } | ||
396 | 186 | |||
397 | 187 | MockSessionAuthorizer& the_mock_session_authorizer() | ||
398 | 188 | { | ||
399 | 189 | return *server_configuration.the_mock_session_authorizer(); | ||
401 | 190 | } | 204 | } |
402 | 191 | 205 | ||
403 | 192 | std::shared_ptr<ms::PromptSessionManager> the_prompt_session_manager() | 206 | std::shared_ptr<ms::PromptSessionManager> the_prompt_session_manager() |
404 | 193 | { | 207 | { |
406 | 194 | return server_config().the_prompt_session_manager(); | 208 | return server.the_prompt_session_manager(); |
407 | 195 | } | 209 | } |
408 | 196 | 210 | ||
409 | 197 | MOCK_METHOD2(prompt_session_state_change, | 211 | MOCK_METHOD2(prompt_session_state_change, |
410 | @@ -240,6 +254,8 @@ | |||
411 | 240 | }; | 254 | }; |
412 | 241 | }; | 255 | }; |
413 | 242 | 256 | ||
414 | 257 | constexpr pid_t PromptSessionClientAPI::application_session_pid; | ||
415 | 258 | |||
416 | 243 | mir_prompt_session_state_change_callback const null_state_change_callback{nullptr}; | 259 | mir_prompt_session_state_change_callback const null_state_change_callback{nullptr}; |
417 | 244 | constexpr char const* const PromptSessionClientAPI::provider_name[]; | 260 | constexpr char const* const PromptSessionClientAPI::provider_name[]; |
418 | 245 | 261 | ||
419 | @@ -417,7 +433,7 @@ | |||
420 | 417 | the_prompt_session_manager()->stop_prompt_session(server_prompt_session); | 433 | the_prompt_session_manager()->stop_prompt_session(server_prompt_session); |
421 | 418 | 434 | ||
422 | 419 | // Verify we have got the "stopped" notification before we go on and release the session | 435 | // Verify we have got the "stopped" notification before we go on and release the session |
424 | 420 | Mock::VerifyAndClearExpectations(the_mock_prompt_session_listener()); | 436 | Mock::VerifyAndClearExpectations(the_mock_prompt_session_listener().get()); |
425 | 421 | 437 | ||
426 | 422 | mir_prompt_session_release_sync(prompt_session); | 438 | mir_prompt_session_release_sync(prompt_session); |
427 | 423 | } | 439 | } |
428 | @@ -493,7 +509,7 @@ | |||
429 | 493 | 509 | ||
430 | 494 | TEST_F(PromptSessionClientAPI, cannot_start_a_prompt_session_without_authorization) | 510 | TEST_F(PromptSessionClientAPI, cannot_start_a_prompt_session_without_authorization) |
431 | 495 | { | 511 | { |
433 | 496 | EXPECT_CALL(the_mock_session_authorizer(), prompt_session_is_allowed(_)) | 512 | EXPECT_CALL(*the_mock_session_authorizer(), prompt_session_is_allowed(_)) |
434 | 497 | .WillOnce(Return(false)); | 513 | .WillOnce(Return(false)); |
435 | 498 | 514 | ||
436 | 499 | connection = mir_connect_sync(new_connection().c_str(), __PRETTY_FUNCTION__); | 515 | connection = mir_connect_sync(new_connection().c_str(), __PRETTY_FUNCTION__); |
437 | @@ -513,9 +529,9 @@ | |||
438 | 513 | TEST_F(PromptSessionClientAPI, | 529 | TEST_F(PromptSessionClientAPI, |
439 | 514 | can_start_a_prompt_session_without_authorization_on_prompt_connection) | 530 | can_start_a_prompt_session_without_authorization_on_prompt_connection) |
440 | 515 | { | 531 | { |
442 | 516 | ON_CALL(the_mock_session_authorizer(), prompt_session_is_allowed(_)) | 532 | ON_CALL(*the_mock_session_authorizer(), prompt_session_is_allowed(_)) |
443 | 517 | .WillByDefault(Return(false)); | 533 | .WillByDefault(Return(false)); |
445 | 518 | EXPECT_CALL(the_mock_session_authorizer(), prompt_session_is_allowed(_)).Times(0); | 534 | EXPECT_CALL(*the_mock_session_authorizer(), prompt_session_is_allowed(_)).Times(0); |
446 | 519 | 535 | ||
447 | 520 | connection = mir_connect_sync(new_prompt_connection().c_str(), __PRETTY_FUNCTION__); | 536 | connection = mir_connect_sync(new_prompt_connection().c_str(), __PRETTY_FUNCTION__); |
448 | 521 | 537 | ||
449 | @@ -539,7 +555,7 @@ | |||
450 | 539 | { | 555 | { |
451 | 540 | connection = mir_connect_sync(new_prompt_connection().c_str(), __PRETTY_FUNCTION__); | 556 | connection = mir_connect_sync(new_prompt_connection().c_str(), __PRETTY_FUNCTION__); |
452 | 541 | 557 | ||
454 | 542 | EXPECT_CALL(the_mock_session_authorizer(), connection_is_allowed(_)).Times(0); | 558 | EXPECT_CALL(*the_mock_session_authorizer(), connection_is_allowed(_)).Times(0); |
455 | 543 | 559 | ||
456 | 544 | MirPromptSession* prompt_session = mir_connection_create_prompt_session_sync( | 560 | MirPromptSession* prompt_session = mir_connection_create_prompt_session_sync( |
457 | 545 | connection, application_session_pid, null_state_change_callback, this); | 561 | connection, application_session_pid, null_state_change_callback, this); |
458 | 546 | 562 | ||
459 | === added file 'tests/include/mir_test_framework/headless_in_process_server.h' | |||
460 | --- tests/include/mir_test_framework/headless_in_process_server.h 1970-01-01 00:00:00 +0000 | |||
461 | +++ tests/include/mir_test_framework/headless_in_process_server.h 2014-10-24 18:38:25 +0000 | |||
462 | @@ -0,0 +1,36 @@ | |||
463 | 1 | /* | ||
464 | 2 | * Copyright © 2014 Canonical Ltd. | ||
465 | 3 | * | ||
466 | 4 | * This program is free software: you can redistribute it and/or modify it | ||
467 | 5 | * under the terms of the GNU General Public License version 3, | ||
468 | 6 | * as published by the Free Software Foundation. | ||
469 | 7 | * | ||
470 | 8 | * This program is distributed in the hope that it will be useful, | ||
471 | 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
472 | 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
473 | 11 | * GNU General Public License for more details. | ||
474 | 12 | * | ||
475 | 13 | * You should have received a copy of the GNU General Public License | ||
476 | 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
477 | 15 | * | ||
478 | 16 | * Authored By: Alan Griffiths <alan@octopull.co.uk> | ||
479 | 17 | */ | ||
480 | 18 | |||
481 | 19 | #ifndef MIR_TEST_FRAMEWORK_HEADLESS_IN_PROCESS_SERVER_H_ | ||
482 | 20 | #define MIR_TEST_FRAMEWORK_HEADLESS_IN_PROCESS_SERVER_H_ | ||
483 | 21 | |||
484 | 22 | #include "mir_test_framework/headless_test.h" | ||
485 | 23 | |||
486 | 24 | namespace mir_test_framework | ||
487 | 25 | { | ||
488 | 26 | struct HeadlessInProcessServer : HeadlessTest | ||
489 | 27 | { | ||
490 | 28 | HeadlessInProcessServer(); | ||
491 | 29 | |||
492 | 30 | void SetUp() override; | ||
493 | 31 | |||
494 | 32 | void TearDown() override; | ||
495 | 33 | }; | ||
496 | 34 | } | ||
497 | 35 | |||
498 | 36 | #endif /* MIR_TEST_FRAMEWORK_HEADLESS_IN_PROCESS_SERVER_H_ */ | ||
499 | 0 | 37 | ||
500 | === modified file 'tests/include/mir_test_framework/headless_test.h' | |||
501 | --- tests/include/mir_test_framework/headless_test.h 2014-10-24 18:38:24 +0000 | |||
502 | +++ tests/include/mir_test_framework/headless_test.h 2014-10-24 18:38:25 +0000 | |||
503 | @@ -54,6 +54,9 @@ | |||
504 | 54 | /// \return a connection string for a new client to connect to the server | 54 | /// \return a connection string for a new client to connect to the server |
505 | 55 | auto new_connection() -> std::string; | 55 | auto new_connection() -> std::string; |
506 | 56 | 56 | ||
507 | 57 | /// \return a connection string for a client to connect to the server | ||
508 | 58 | auto connection(int fd) -> std::string; | ||
509 | 59 | |||
510 | 57 | mir::Server server; | 60 | mir::Server server; |
511 | 58 | 61 | ||
512 | 59 | private: | 62 | private: |
513 | 60 | 63 | ||
514 | === modified file 'tests/mir_test_framework/CMakeLists.txt' | |||
515 | --- tests/mir_test_framework/CMakeLists.txt 2014-10-24 18:38:24 +0000 | |||
516 | +++ tests/mir_test_framework/CMakeLists.txt 2014-10-24 18:38:25 +0000 | |||
517 | @@ -15,6 +15,7 @@ | |||
518 | 15 | executable_path.cpp | 15 | executable_path.cpp |
519 | 16 | command_line_server_configuration.cpp | 16 | command_line_server_configuration.cpp |
520 | 17 | cross_process_sync.cpp | 17 | cross_process_sync.cpp |
521 | 18 | headless_in_process_server.cpp | ||
522 | 18 | headless_test.cpp | 19 | headless_test.cpp |
523 | 19 | server_runner.cpp | 20 | server_runner.cpp |
524 | 20 | temporary_environment_value.cpp | 21 | temporary_environment_value.cpp |
525 | 21 | 22 | ||
526 | === added file 'tests/mir_test_framework/headless_in_process_server.cpp' | |||
527 | --- tests/mir_test_framework/headless_in_process_server.cpp 1970-01-01 00:00:00 +0000 | |||
528 | +++ tests/mir_test_framework/headless_in_process_server.cpp 2014-10-24 18:38:25 +0000 | |||
529 | @@ -0,0 +1,36 @@ | |||
530 | 1 | /* | ||
531 | 2 | * Copyright © 2014 Canonical Ltd. | ||
532 | 3 | * | ||
533 | 4 | * This program is free software: you can redistribute it and/or modify it | ||
534 | 5 | * under the terms of the GNU General Public License version 3, | ||
535 | 6 | * as published by the Free Software Foundation. | ||
536 | 7 | * | ||
537 | 8 | * This program is distributed in the hope that it will be useful, | ||
538 | 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
539 | 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
540 | 11 | * GNU General Public License for more details. | ||
541 | 12 | * | ||
542 | 13 | * You should have received a copy of the GNU General Public License | ||
543 | 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
544 | 15 | * | ||
545 | 16 | * Authored By: Alan Griffiths <alan@octopull.co.uk> | ||
546 | 17 | */ | ||
547 | 18 | |||
548 | 19 | #include "mir_test_framework/headless_in_process_server.h" | ||
549 | 20 | |||
550 | 21 | namespace mtf = mir_test_framework; | ||
551 | 22 | |||
552 | 23 | mtf::HeadlessInProcessServer::HeadlessInProcessServer() | ||
553 | 24 | { | ||
554 | 25 | add_to_environment("MIR_SERVER_NO_FILE", ""); | ||
555 | 26 | } | ||
556 | 27 | |||
557 | 28 | void mtf::HeadlessInProcessServer::SetUp() | ||
558 | 29 | { | ||
559 | 30 | start_server(); | ||
560 | 31 | } | ||
561 | 32 | |||
562 | 33 | void mtf::HeadlessInProcessServer::TearDown() | ||
563 | 34 | { | ||
564 | 35 | stop_server(); | ||
565 | 36 | } | ||
566 | 0 | 37 | ||
567 | === modified file 'tests/mir_test_framework/headless_test.cpp' | |||
568 | --- tests/mir_test_framework/headless_test.cpp 2014-10-24 18:38:24 +0000 | |||
569 | +++ tests/mir_test_framework/headless_test.cpp 2014-10-24 18:38:25 +0000 | |||
570 | @@ -103,7 +103,12 @@ | |||
571 | 103 | 103 | ||
572 | 104 | auto mtf::HeadlessTest::new_connection() -> std::string | 104 | auto mtf::HeadlessTest::new_connection() -> std::string |
573 | 105 | { | 105 | { |
574 | 106 | return connection(server.open_client_socket()); | ||
575 | 107 | } | ||
576 | 108 | |||
577 | 109 | auto mtf::HeadlessTest::connection(int fd) -> std::string | ||
578 | 110 | { | ||
579 | 106 | char connect_string[64] = {0}; | 111 | char connect_string[64] = {0}; |
581 | 107 | sprintf(connect_string, "fd://%d", server.open_client_socket()); | 112 | sprintf(connect_string, "fd://%d", fd); |
582 | 108 | return connect_string; | 113 | return connect_string; |
583 | 109 | } | 114 | } |