Mir

Merge lp:~alan-griffiths/mir/migrate-more-acceptances-tests into lp:mir

Proposed by Alan Griffiths
Status: Merged
Approved by: Cemil Azizoglu
Approved revision: no longer in the source branch.
Merged at revision: 2073
Proposed branch: lp:~alan-griffiths/mir/migrate-more-acceptances-tests
Merge into: lp:mir
Diff against target: 772 lines (+303/-256)
9 files modified
tests/acceptance-tests/test_client_library_errors.cpp (+3/-13)
tests/acceptance-tests/test_client_surface_events.cpp (+26/-35)
tests/acceptance-tests/test_client_surface_swap_buffers.cpp (+2/-30)
tests/acceptance-tests/test_server_disconnect.cpp (+148/-172)
tests/include/mir_test_framework/connected_client_with_a_surface.h (+36/-0)
tests/include/mir_test_framework/interprocess_client_server_test.h (+7/-0)
tests/mir_test_framework/CMakeLists.txt (+1/-0)
tests/mir_test_framework/connected_client_with_a_surface.cpp (+44/-0)
tests/mir_test_framework/interprocess_client_server_test.cpp (+36/-6)
To merge this branch: bzr merge lp:~alan-griffiths/mir/migrate-more-acceptances-tests
Reviewer Review Type Date Requested Status
PS Jenkins bot (community) continuous-integration Approve
Cemil Azizoglu (community) Approve
Alexandros Frantzis (community) Approve
Review via email: mp+242094@code.launchpad.net

Commit message

tests: migrate some more acceptance tests to the mir::Server API

Description of the change

tests: migrate some more acceptance tests to the mir::Server API

I think this covers all the tests that cam be trivially reworked.

The remaining tests customize functionality for which there is no longer a customization point. (E.g. faking the event hub, customizing the display configuration within the stubbed graphics, or other classes that DefaultServerConfiguration exposed.)

I'm going to work on proposing those individually as there are decisions (and potential discussion) needed about what should be a supported customization point and how it should be made available.

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Alexandros Frantzis (afrantzis) wrote :

Looks good.

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

 RUN ] MesaBufferAllocatorTest.software_buffers_dont_bypass
unknown file: Failure
C++ exception with description "Failed to open temporary file" thrown in the test body.
[ FAILED ] MesaBufferAllocatorTest.software_buffers_dont_bypass (150 ms)
...
[ RUN ] MesaBufferAllocatorTest.creates_software_rendering_buffer
unknown file: Failure
C++ exception with description "Failed to open temporary file" thrown in the test body.
[ FAILED ] MesaBufferAllocatorTest.creates_software_rendering_buffer (137 ms)
...
[ RUN ] AnonymousShmFile.is_created
unknown file: Failure
C++ exception with description "Failed to open temporary file" thrown in the test body.
[ FAILED ] AnonymousShmFile.is_created (3 ms)
[ RUN ] AnonymousShmFile.writing_to_base_ptr_writes_to_file
unknown file: Failure
C++ exception with description "Failed to open temporary file" thrown in the test body.
[ FAILED ] AnonymousShmFile.writing_to_base_ptr_writes_to_file (3 ms)

IIRC these tests fail on CI's old kernel and should be filtered. Investigating...

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

> IIRC these tests fail on CI's old kernel and should be filtered.
> Investigating...

cmake/MirCommon.cmake:

    # Some tests expect kernel version 3.11 and up
    if (${KERNEL_VERSION} VERSION_LESS "3.11")
        add_test(${EXECUTABLE} ${VALGRIND_EXECUTABLE} ${VALGRIND_ARGS} ${EXECUTABLE_OUTPUT_PATH}/${EXECUTABLE}
            "--gtest_filter=-*DeathTest.*:AnonymousShmFile.*:MesaBufferAllocatorTest.software_buffers_dont_bypass:MesaBufferAllocatorTest.creates_software_rendering_buffer")

From the failing console: "-- Kernel version detected: 3.13"

So we should be running the tests (and they ought to be passing).

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

Logged as lp:1394278

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 :

fginther disabled the host where tests have failed. Apparently it was a machine that was a newly created cloud instance. He is to follow up and root-cause it on his side. He suggested we re-TA.

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

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'tests/acceptance-tests/test_client_library_errors.cpp'
--- tests/acceptance-tests/test_client_library_errors.cpp 2014-11-05 10:17:05 +0000
+++ tests/acceptance-tests/test_client_library_errors.cpp 2014-11-18 16:56:14 +0000
@@ -25,8 +25,7 @@
2525
26#include "mir_test/validity_matchers.h"26#include "mir_test/validity_matchers.h"
2727
28#include "mir_test_framework/in_process_server.h"28#include "mir_test_framework/headless_in_process_server.h"
29#include "mir_test_framework/stubbed_server_configuration.h"
30#include "mir_test_framework/using_stub_client_platform.h"29#include "mir_test_framework/using_stub_client_platform.h"
31#include "mir_test_framework/stub_client_connection_configuration.h"30#include "mir_test_framework/stub_client_connection_configuration.h"
3231
@@ -132,19 +131,10 @@
132 return std::make_shared<ConfigurableFailureFactory<failure_set>>();131 return std::make_shared<ConfigurableFailureFactory<failure_set>>();
133 }132 }
134};133};
135
136class ClientLibraryErrors : public mtf::InProcessServer
137{
138private:
139 mtf::StubbedServerConfiguration config;
140
141 mir::DefaultServerConfiguration &server_config() override
142 {
143 return config;
144 }
145};
146}134}
147135
136using ClientLibraryErrors = mtf::HeadlessInProcessServer;
137
148TEST_F(ClientLibraryErrors, exception_in_client_configuration_constructor_generates_error)138TEST_F(ClientLibraryErrors, exception_in_client_configuration_constructor_generates_error)
149{139{
150 mtf::UsingClientPlatform<ConfigurableFailureConfiguration<Method::the_client_platform_factory>> stubby;140 mtf::UsingClientPlatform<ConfigurableFailureConfiguration<Method::the_client_platform_factory>> stubby;
151141
=== modified file 'tests/acceptance-tests/test_client_surface_events.cpp'
--- tests/acceptance-tests/test_client_surface_events.cpp 2014-10-27 22:31:16 +0000
+++ tests/acceptance-tests/test_client_surface_events.cpp 2014-11-18 16:56:14 +0000
@@ -24,8 +24,7 @@
24#include "mir/scene/surface.h"24#include "mir/scene/surface.h"
25#include "mir/scene/surface_creation_parameters.h"25#include "mir/scene/surface_creation_parameters.h"
2626
27#include "mir_test_framework/stubbed_server_configuration.h"27#include "mir_test_framework/connected_client_with_a_surface.h"
28#include "mir_test_framework/basic_client_server_fixture.h"
2928
30#include <gtest/gtest.h>29#include <gtest/gtest.h>
31#include <gmock/gmock.h>30#include <gmock/gmock.h>
@@ -60,32 +59,7 @@
60 std::shared_ptr<ms::Surface> latest_surface;59 std::shared_ptr<ms::Surface> latest_surface;
61};60};
6261
63struct MyConfig : mtf::StubbedServerConfiguration62struct ClientSurfaceEvents : mtf::ConnectedClientWithASurface
64{
65 std::shared_ptr<ms::SurfaceCoordinator> wrap_surface_coordinator(
66 std::shared_ptr<ms::SurfaceCoordinator> const& wrapped) override
67 {
68 auto const msc = std::make_shared<MockSurfaceCoordinator>(wrapped);
69 mock_surface_coordinator = msc;
70 return msc;
71 }
72
73 std::shared_ptr<MockSurfaceCoordinator> the_mock_surface_coordinator() const
74 {
75 return mock_surface_coordinator.lock();
76 }
77
78 std::shared_ptr<ms::Surface> the_latest_surface() const
79 {
80 return the_mock_surface_coordinator()->latest_surface;
81 }
82
83 std::weak_ptr<MockSurfaceCoordinator> mock_surface_coordinator;
84};
85
86using BasicClientServerFixture = mtf::BasicClientServerFixture<MyConfig>;
87
88struct ClientSurfaceEvents : BasicClientServerFixture
89{63{
90 MirSurfaceParameters const request_params64 MirSurfaceParameters const request_params
91 {65 {
@@ -96,7 +70,6 @@
96 mir_display_output_id_invalid70 mir_display_output_id_invalid
97 };71 };
9872
99 MirSurface* surface{nullptr};
100 MirSurface* other_surface;73 MirSurface* other_surface;
10174
102 std::mutex last_event_mutex;75 std::mutex last_event_mutex;
@@ -139,14 +112,31 @@
139 last_event_surface = nullptr;112 last_event_surface = nullptr;
140 }113 }
141114
115 std::shared_ptr<MockSurfaceCoordinator> the_mock_surface_coordinator() const
116 {
117 return mock_surface_coordinator.lock();
118 }
119
120 std::shared_ptr<ms::Surface> the_latest_surface() const
121 {
122 return the_mock_surface_coordinator()->latest_surface;
123 }
124
142 void SetUp() override125 void SetUp() override
143 {126 {
144 BasicClientServerFixture::SetUp();127 server.wrap_surface_coordinator([&](std::shared_ptr<ms::SurfaceCoordinator> const& wrapped)
145128 -> std::shared_ptr<ms::SurfaceCoordinator>
146 surface = mir_connection_create_surface_sync(connection, &request_params);129 {
130 auto const msc = std::make_shared<MockSurfaceCoordinator>(wrapped);
131 mock_surface_coordinator = msc;
132 return msc;
133 });
134
135 mtf::ConnectedClientWithASurface::SetUp();
136
147 mir_surface_set_event_handler(surface, &delegate);137 mir_surface_set_event_handler(surface, &delegate);
148138
149 scene_surface = server_configuration.the_latest_surface();139 scene_surface = the_latest_surface();
150140
151 other_surface = mir_connection_create_surface_sync(connection, &request_params);141 other_surface = mir_connection_create_surface_sync(connection, &request_params);
152 mir_surface_set_event_handler(other_surface, nullptr);142 mir_surface_set_event_handler(other_surface, nullptr);
@@ -158,10 +148,11 @@
158 {148 {
159 mir_surface_release_sync(other_surface);149 mir_surface_release_sync(other_surface);
160 scene_surface.reset();150 scene_surface.reset();
161 mir_surface_release_sync(surface);
162151
163 BasicClientServerFixture::TearDown();152 mtf::ConnectedClientWithASurface::TearDown();
164 }153 }
154
155 std::weak_ptr<MockSurfaceCoordinator> mock_surface_coordinator;
165};156};
166}157}
167158
168159
=== modified file 'tests/acceptance-tests/test_client_surface_swap_buffers.cpp'
--- tests/acceptance-tests/test_client_surface_swap_buffers.cpp 2014-11-18 03:21:20 +0000
+++ tests/acceptance-tests/test_client_surface_swap_buffers.cpp 2014-11-18 16:56:14 +0000
@@ -18,7 +18,7 @@
1818
19#include "mir_toolkit/mir_client_library.h"19#include "mir_toolkit/mir_client_library.h"
2020
21#include "mir_test_framework/connected_client_headless_server.h"21#include "mir_test_framework/connected_client_with_a_surface.h"
22#include "mir_test_doubles/null_display_buffer_compositor_factory.h"22#include "mir_test_doubles/null_display_buffer_compositor_factory.h"
23#include "mir_test/signal.h"23#include "mir_test/signal.h"
2424
@@ -38,35 +38,7 @@
38 buffers_swapped->raise();38 buffers_swapped->raise();
39}39}
4040
41struct ConnectedClientWithASurface : mtf::ConnectedClientHeadlessServer41struct SurfaceSwapBuffers : mtf::ConnectedClientWithASurface
42{
43 MirSurface* surface{nullptr};
44
45 void SetUp() override
46 {
47 mtf::ConnectedClientHeadlessServer::SetUp();
48
49 MirSurfaceParameters request_params =
50 {
51 __PRETTY_FUNCTION__,
52 640, 480,
53 mir_pixel_format_abgr_8888,
54 mir_buffer_usage_hardware,
55 mir_display_output_id_invalid
56 };
57
58 surface = mir_connection_create_surface_sync(connection, &request_params);
59 ASSERT_TRUE(mir_surface_is_valid(surface));
60 }
61
62 void TearDown() override
63 {
64 mir_surface_release_sync(surface);
65 mtf::ConnectedClientHeadlessServer::TearDown();
66 }
67};
68
69struct SurfaceSwapBuffers : ConnectedClientWithASurface
70{42{
71 void SetUp() override43 void SetUp() override
72 {44 {
7345
=== modified file 'tests/acceptance-tests/test_server_disconnect.cpp'
--- tests/acceptance-tests/test_server_disconnect.cpp 2014-11-11 15:50:11 +0000
+++ tests/acceptance-tests/test_server_disconnect.cpp 2014-11-18 16:56:14 +0000
@@ -18,8 +18,9 @@
1818
19#include "mir_toolkit/mir_client_library.h"19#include "mir_toolkit/mir_client_library.h"
2020
21#include "mir_test_framework/display_server_test_fixture.h"21#include "mir_test_framework/interprocess_client_server_test.h"
22#include "mir_test_framework/cross_process_sync.h"22#include "mir_test_framework/cross_process_sync.h"
23#include "mir_test_framework/process.h"
23#include "mir_test/cross_process_action.h"24#include "mir_test/cross_process_action.h"
2425
25#include <gtest/gtest.h>26#include <gtest/gtest.h>
@@ -30,10 +31,17 @@
30namespace mtf = mir_test_framework;31namespace mtf = mir_test_framework;
31namespace mt = mir::test;32namespace mt = mir::test;
3233
33using ServerDisconnect = mtf::BespokeDisplayServerTestFixture;
34
35namespace34namespace
36{35{
36struct ServerDisconnect : mtf::InterprocessClientServerTest
37{
38 void SetUp() override
39 {
40 mtf::InterprocessClientServerTest::SetUp();
41 run_in_server([]{});
42 }
43};
44
37struct MockEventHandler45struct MockEventHandler
38{46{
39 MOCK_METHOD1(handle, void(MirLifecycleState transition));47 MOCK_METHOD1(handle, void(MirLifecycleState transition));
@@ -44,61 +52,132 @@
44 }52 }
45};53};
4654
47struct MyTestingClientConfiguration : mtf::TestingClientConfiguration55void null_lifecycle_callback(MirConnection*, MirLifecycleState, void*)
48{56{
49 void exec() override57}
50 {58}
51 static MirSurfaceParameters const params =59
52 { __PRETTY_FUNCTION__, 33, 45, mir_pixel_format_abgr_8888,60TEST_F(ServerDisconnect, is_detected_by_client)
53 mir_buffer_usage_hardware, mir_display_output_id_invalid };61{
54
55 MockEventHandler mock_event_handler;
56
57 auto connection = mir_connect_sync(mtf::test_socket_file().c_str() , __PRETTY_FUNCTION__);
58 mir_connection_set_lifecycle_event_callback(connection, &MockEventHandler::handle, &mock_event_handler);
59 auto surface = mir_connection_create_surface_sync(connection, &params);
60
61 std::atomic<bool> signalled(false);
62
63 EXPECT_CALL(mock_event_handler, handle(mir_lifecycle_connection_lost)).Times(1).
64 WillOnce(testing::InvokeWithoutArgs([&] { signalled.store(true); }));
65
66 sync.signal_ready();
67
68 using clock = std::chrono::high_resolution_clock;
69
70 auto time_limit = clock::now() + std::chrono::seconds(2);
71
72 while (!signalled.load() && clock::now() < time_limit)
73 {
74 mir_surface_swap_buffers_sync(surface);
75 }
76 mir_surface_release_sync(surface);
77 mir_connection_release(connection);
78 }
79
80 mtf::CrossProcessSync sync;62 mtf::CrossProcessSync sync;
81};63
8264 auto const client = new_client_process([&]
83struct DisconnectingTestingClientConfiguration : mtf::TestingClientConfiguration65 {
84{66 static MirSurfaceParameters const params =
85 void exec() override67 { __PRETTY_FUNCTION__, 33, 45, mir_pixel_format_abgr_8888,
86 {68 mir_buffer_usage_hardware, mir_display_output_id_invalid };
87 MirConnection* connection{nullptr};69
8870 MockEventHandler mock_event_handler;
89 connect.exec([&] {71
90 connection = mir_connect_sync(mtf::test_socket_file().c_str() , __PRETTY_FUNCTION__);72 auto connection = mir_connect_sync(mtf::test_socket_file().c_str() , __PRETTY_FUNCTION__);
91 EXPECT_TRUE(mir_connection_is_valid(connection));73 mir_connection_set_lifecycle_event_callback(connection, &MockEventHandler::handle, &mock_event_handler);
92 /*74 auto surface = mir_connection_create_surface_sync(connection, &params);
93 * Set a null callback to avoid killing the process75
94 * (default callback raises SIGHUP).76 std::atomic<bool> signalled(false);
95 */77
96 mir_connection_set_lifecycle_event_callback(connection,78 EXPECT_CALL(mock_event_handler, handle(mir_lifecycle_connection_lost)).Times(1).
97 null_lifecycle_callback,79 WillOnce(testing::InvokeWithoutArgs([&] { signalled.store(true); }));
98 nullptr);80
99 });81 sync.signal_ready();
10082
101 create_surface.exec([&] {83 using clock = std::chrono::high_resolution_clock;
84
85 auto time_limit = clock::now() + std::chrono::seconds(2);
86
87 while (!signalled.load() && clock::now() < time_limit)
88 {
89 mir_surface_swap_buffers_sync(surface);
90 }
91 mir_surface_release_sync(surface);
92 mir_connection_release(connection);
93 });
94
95 if (is_test_process())
96 {
97 sync.wait_for_signal_ready_for();
98 stop_server();
99 }
100}
101
102TEST_F(ServerDisconnect, doesnt_stop_client_calling_API_functions)
103{
104 mt::CrossProcessAction connect;
105 mt::CrossProcessAction create_surface;
106 mt::CrossProcessAction configure_display;
107 mt::CrossProcessAction disconnect;
108
109 auto const client = new_client_process([&]
110 {
111 MirConnection* connection{nullptr};
112
113 connect.exec([&] {
114 connection = mir_connect_sync(mtf::test_socket_file().c_str() , __PRETTY_FUNCTION__);
115 EXPECT_TRUE(mir_connection_is_valid(connection));
116 /*
117 * Set a null callback to avoid killing the process
118 * (default callback raises SIGHUP).
119 */
120 mir_connection_set_lifecycle_event_callback(connection,
121 null_lifecycle_callback,
122 nullptr);
123 });
124
125 MirSurface* surf;
126
127 create_surface.exec([&] {
128 MirSurfaceParameters const parameters =
129 {
130 __PRETTY_FUNCTION__,
131 1, 1,
132 mir_pixel_format_abgr_8888,
133 mir_buffer_usage_hardware,
134 mir_display_output_id_invalid
135 };
136 surf = mir_connection_create_surface_sync(connection, &parameters);
137 });
138
139 configure_display.exec([&] {
140 auto config = mir_connection_create_display_config(connection);
141 mir_wait_for(mir_connection_apply_display_config(connection, config));
142 mir_display_config_destroy(config);
143 });
144
145 disconnect.exec([&] {
146 mir_surface_release_sync(surf);
147 mir_connection_release(connection);
148 });
149 });
150
151 if (is_test_process())
152 {
153 connect();
154 stop_server();
155 /* While trying to create a surface the connection break will be detected */
156 create_surface();
157
158 /* Trying to configure the display shouldn't block */
159 configure_display();
160 /* Trying to disconnect at this point shouldn't block */
161 disconnect();
162 }
163}
164
165TEST_F(ServerDisconnect, causes_client_to_terminate_by_default)
166{
167 mt::CrossProcessAction connect;
168 mtf::CrossProcessSync create_surface_sync;
169
170 auto const client = new_client_process([&]
171 {
172 MirConnection* connection{nullptr};
173
174 connect.exec([&] {
175 connection = mir_connect_sync(mtf::test_socket_file().c_str() , __PRETTY_FUNCTION__);
176 EXPECT_TRUE(mir_connection_is_valid(connection));
177 });
178
179 create_surface_sync.wait_for_signal_ready_for();
180
102 MirSurfaceParameters const parameters =181 MirSurfaceParameters const parameters =
103 {182 {
104 __PRETTY_FUNCTION__,183 __PRETTY_FUNCTION__,
@@ -107,129 +186,26 @@
107 mir_buffer_usage_hardware,186 mir_buffer_usage_hardware,
108 mir_display_output_id_invalid187 mir_display_output_id_invalid
109 };188 };
110 surf = mir_connection_create_surface_sync(connection, &parameters);189 mir_connection_create_surface_sync(connection, &parameters);
111 });190
112
113 configure_display.exec([&] {
114 auto config = mir_connection_create_display_config(connection);
115 mir_wait_for(mir_connection_apply_display_config(connection, config));
116 mir_display_config_destroy(config);
117 });
118
119 disconnect.exec([&] {
120 mir_surface_release_sync(surf);
121 mir_connection_release(connection);191 mir_connection_release(connection);
122 });192 });
123 }193
124194 if (is_test_process())
125 static void null_lifecycle_callback(MirConnection*, MirLifecycleState, void*)195 {
126 {196 connect();
127 }197 stop_server();
128
129 mt::CrossProcessAction connect;
130 mt::CrossProcessAction create_surface;
131 mt::CrossProcessAction configure_display;
132 mt::CrossProcessAction disconnect;
133private:
134 MirSurface* surf;
135};
136
137/*
138 * This client will self-terminate on server connection break (through the default
139 * lifecycle handler).
140 */
141struct TerminatingTestingClientConfiguration : mtf::TestingClientConfiguration
142{
143 void exec() override
144 {
145 MirConnection* connection{nullptr};
146
147 connect.exec([&] {
148 connection = mir_connect_sync(mtf::test_socket_file().c_str() , __PRETTY_FUNCTION__);
149 EXPECT_TRUE(mir_connection_is_valid(connection));
150 });
151
152 create_surface_sync.wait_for_signal_ready_for();
153
154 MirSurfaceParameters const parameters =
155 {
156 __PRETTY_FUNCTION__,
157 1, 1,
158 mir_pixel_format_abgr_8888,
159 mir_buffer_usage_hardware,
160 mir_display_output_id_invalid
161 };
162 mir_connection_create_surface_sync(connection, &parameters);
163
164 mir_connection_release(connection);
165 }
166
167 mt::CrossProcessAction connect;
168 mtf::CrossProcessSync create_surface_sync;
169};
170}
171
172TEST_F(ServerDisconnect, client_detects_server_shutdown)
173{
174 TestingServerConfiguration server_config;
175 launch_server_process(server_config);
176
177 MyTestingClientConfiguration client_config;
178 launch_client_process(client_config);
179
180 run_in_test_process([this, &client_config]
181 {
182 client_config.sync.wait_for_signal_ready_for();
183 shutdown_server_process();
184 });
185}
186
187TEST_F(ServerDisconnect, client_can_call_connection_functions_after_connection_break_is_detected)
188{
189 TestingServerConfiguration server_config;
190 launch_server_process(server_config);
191
192 DisconnectingTestingClientConfiguration client_config;
193 launch_client_process(client_config);
194
195 run_in_test_process([this, &client_config]
196 {
197 client_config.connect();
198 shutdown_server_process();
199 /* While trying to create a surface the connection break will be detected */
200 client_config.create_surface();
201
202 /* Trying to configure the display shouldn't block */
203 client_config.configure_display();
204 /* Trying to disconnect at this point shouldn't block */
205 client_config.disconnect();
206 });
207}
208
209TEST_F(ServerDisconnect, causes_client_to_terminate_by_default)
210{
211 TestingServerConfiguration server_config;
212 launch_server_process(server_config);
213
214 TerminatingTestingClientConfiguration client_config;
215 launch_client_process(client_config);
216
217 run_in_test_process([this, &client_config]
218 {
219 client_config.connect();
220 shutdown_server_process();
221198
222 /*199 /*
223 * While trying to create a surface the connection break will be detected200 * While trying to create a surface the connection break will be detected
224 * and the client should self-terminate.201 * and the client should self-terminate.
225 */202 */
226 client_config.create_surface_sync.signal_ready();203 create_surface_sync.signal_ready();
227204
228 auto const client_results = wait_for_shutdown_client_processes();205 auto const client_result = client->wait_for_termination();
229 ASSERT_EQ(1, client_results.size());
230 EXPECT_EQ(mtf::TerminationReason::child_terminated_by_signal,206 EXPECT_EQ(mtf::TerminationReason::child_terminated_by_signal,
231 client_results[0].reason);207 client_result.reason);
232 int sig = client_results[0].signal;208 int sig = client_result.signal;
233 EXPECT_TRUE(sig == SIGHUP || sig == SIGKILL /* (Valgrind) */);209 EXPECT_TRUE(sig == SIGHUP || sig == SIGKILL /* (Valgrind) */);
234 });210 }
235}211}
236212
=== added file 'tests/include/mir_test_framework/connected_client_with_a_surface.h'
--- tests/include/mir_test_framework/connected_client_with_a_surface.h 1970-01-01 00:00:00 +0000
+++ tests/include/mir_test_framework/connected_client_with_a_surface.h 2014-11-18 16:56:14 +0000
@@ -0,0 +1,36 @@
1/*
2 * Copyright © 2014 Canonical Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License version 3,
6 * as published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Authored By: Alan Griffiths <alan@octopull.co.uk>
17 */
18
19#ifndef MIR_TEST_FRAMEWORK_CONNECTED_CLIENT_WITH_A_SURFACE_H_
20#define MIR_TEST_FRAMEWORK_CONNECTED_CLIENT_WITH_A_SURFACE_H_
21
22#include "mir_test_framework/connected_client_headless_server.h"
23
24namespace mir_test_framework
25{
26struct ConnectedClientWithASurface : ConnectedClientHeadlessServer
27{
28 MirSurface* surface{nullptr};
29
30 void SetUp() override;
31
32 void TearDown() override;
33};
34}
35
36#endif /* MIR_TEST_FRAMEWORK_CONNECTED_CLIENT_WITH_A_SURFACE_H_ */
037
=== modified file 'tests/include/mir_test_framework/interprocess_client_server_test.h'
--- tests/include/mir_test_framework/interprocess_client_server_test.h 2014-11-18 03:21:20 +0000
+++ tests/include/mir_test_framework/interprocess_client_server_test.h 2014-11-18 16:56:14 +0000
@@ -25,6 +25,7 @@
25namespace mir_test_framework25namespace mir_test_framework
26{26{
27class Process;27class Process;
28class Result;
2829
29class InterprocessClientServerTest : public HeadlessTest30class InterprocessClientServerTest : public HeadlessTest
30{31{
@@ -39,6 +40,8 @@
3940
40 void run_in_client(std::function<void()> const& client_code);41 void run_in_client(std::function<void()> const& client_code);
4142
43 auto new_client_process(std::function<void()> const& client_code) -> std::shared_ptr<Process>;
44
42 bool is_test_process() const;45 bool is_test_process() const;
4346
44 pid_t client_pid() const { return client_process_id; }47 pid_t client_pid() const { return client_process_id; }
@@ -50,8 +53,12 @@
5053
51 void expect_server_signalled(int signal);54 void expect_server_signalled(int signal);
5255
56 void stop_server();
57
53 bool sigkill_server_process();58 bool sigkill_server_process();
5459
60 Result wait_for_shutdown_server_process();
61
55private:62private:
5663
57 pid_t test_process_id{getpid()};64 pid_t test_process_id{getpid()};
5865
=== modified file 'tests/mir_test_framework/CMakeLists.txt'
--- tests/mir_test_framework/CMakeLists.txt 2014-11-18 03:21:20 +0000
+++ tests/mir_test_framework/CMakeLists.txt 2014-11-18 16:56:14 +0000
@@ -15,6 +15,7 @@
15 executable_path.cpp15 executable_path.cpp
16 command_line_server_configuration.cpp16 command_line_server_configuration.cpp
17 connected_client_headless_server.cpp17 connected_client_headless_server.cpp
18 connected_client_with_a_surface.cpp
18 cross_process_sync.cpp19 cross_process_sync.cpp
19 headless_in_process_server.cpp20 headless_in_process_server.cpp
20 headless_test.cpp21 headless_test.cpp
2122
=== added file 'tests/mir_test_framework/connected_client_with_a_surface.cpp'
--- tests/mir_test_framework/connected_client_with_a_surface.cpp 1970-01-01 00:00:00 +0000
+++ tests/mir_test_framework/connected_client_with_a_surface.cpp 2014-11-18 16:56:14 +0000
@@ -0,0 +1,44 @@
1/*
2 * Copyright © 2014 Canonical Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License version 3,
6 * as published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Authored By: Alan Griffiths <alan@octopull.co.uk>
17 */
18
19#include "mir_test_framework/connected_client_with_a_surface.h"
20
21namespace mtf = mir_test_framework;
22
23void mtf::ConnectedClientWithASurface::SetUp()
24{
25 ConnectedClientHeadlessServer::SetUp();
26
27 MirSurfaceParameters request_params =
28 {
29 __PRETTY_FUNCTION__,
30 640, 480,
31 mir_pixel_format_abgr_8888,
32 mir_buffer_usage_hardware,
33 mir_display_output_id_invalid
34 };
35
36 surface = mir_connection_create_surface_sync(connection, &request_params);
37 ASSERT_TRUE(mir_surface_is_valid(surface));
38}
39
40void mtf::ConnectedClientWithASurface::TearDown()
41{
42 mir_surface_release_sync(surface);
43 ConnectedClientHeadlessServer::TearDown();
44}
045
=== modified file 'tests/mir_test_framework/interprocess_client_server_test.cpp'
--- tests/mir_test_framework/interprocess_client_server_test.cpp 2014-11-18 03:21:20 +0000
+++ tests/mir_test_framework/interprocess_client_server_test.cpp 2014-11-18 16:56:14 +0000
@@ -82,8 +82,20 @@
8282
83void mtf::InterprocessClientServerTest::run_in_client(std::function<void()> const& client_code)83void mtf::InterprocessClientServerTest::run_in_client(std::function<void()> const& client_code)
84{84{
85 auto const client_process = new_client_process(client_code);
86
85 if (test_process_id != getpid()) return;87 if (test_process_id != getpid()) return;
8688
89 Result result = client_process->wait_for_termination();
90 EXPECT_THAT(result.exit_code, Eq(EXIT_SUCCESS));
91}
92
93auto mtf::InterprocessClientServerTest::new_client_process(std::function<void()> const& client_code)
94-> std::shared_ptr<Process>
95{
96 if (test_process_id != getpid())
97 return std::shared_ptr<Process>{};
98
87 pid_t pid = fork();99 pid_t pid = fork();
88100
89 if (pid < 0)101 if (pid < 0)
@@ -96,13 +108,12 @@
96 process_tag = "client";108 process_tag = "client";
97 add_to_environment("MIR_SOCKET", mir_test_socket);109 add_to_environment("MIR_SOCKET", mir_test_socket);
98 client_code();110 client_code();
111 return std::shared_ptr<Process>{};
99 }112 }
100 else113 else
101 {114 {
102 client_process_id = pid;115 client_process_id = pid;
103 auto const client_process = std::make_shared<Process>(pid);116 return std::make_shared<Process>(pid);
104 Result result = client_process->wait_for_termination();
105 EXPECT_THAT(result.exit_code, Eq(EXIT_SUCCESS));
106 }117 }
107}118}
108119
@@ -116,7 +127,16 @@
116 if (server_process_id == getpid())127 if (server_process_id == getpid())
117 {128 {
118 shutdown_sync.wait_for_signal_ready_for();129 shutdown_sync.wait_for_signal_ready_for();
119 stop_server();130 }
131
132 stop_server();
133}
134
135void mtf::InterprocessClientServerTest::stop_server()
136{
137 if (server_process_id == getpid())
138 {
139 HeadlessTest::stop_server();
120 }140 }
121141
122 if (test_process_id != getpid()) return;142 if (test_process_id != getpid()) return;
@@ -156,9 +176,19 @@
156 throw std::logic_error("No server process to kill");176 throw std::logic_error("No server process to kill");
157177
158 server_process->kill();178 server_process->kill();
159 auto result = server_process->wait_for_termination();179 auto result = wait_for_shutdown_server_process();
160 server_process.reset();
161180
162 return result.reason == TerminationReason::child_terminated_by_signal &&181 return result.reason == TerminationReason::child_terminated_by_signal &&
163 result.signal == SIGKILL;182 result.signal == SIGKILL;
164}183}
184
185mtf::Result mtf::InterprocessClientServerTest::wait_for_shutdown_server_process()
186{
187
188 if (!server_process)
189 throw std::logic_error("No server process to monitor");
190
191 Result result = server_process->wait_for_termination();
192 server_process.reset();
193 return result;
194}

Subscribers

People subscribed via source and target branches