Mir

Merge lp:~alan-griffiths/mir/migrate-tests-to-miral into lp:mir

Proposed by Alan Griffiths
Status: Merged
Approved by: Gerry Boland
Approved revision: no longer in the source branch.
Merged at revision: 4260
Proposed branch: lp:~alan-griffiths/mir/migrate-tests-to-miral
Merge into: lp:mir
Diff against target: 319 lines (+114/-37)
6 files modified
include/test/mir_test_framework/async_server_runner.h (+13/-1)
include/test/mir_test_framework/canonical_window_manager_policy.h (+38/-0)
tests/CMakeLists.txt (+4/-0)
tests/acceptance-tests/test_client_surfaces.cpp (+47/-24)
tests/mir_test_framework/async_server_runner.cpp (+10/-2)
tests/performance-tests/CMakeLists.txt (+2/-10)
To merge this branch: bzr merge lp:~alan-griffiths/mir/migrate-tests-to-miral
Reviewer Review Type Date Requested Status
Gerry Boland (community) Approve
Mir CI Bot continuous-integration Approve
Review via email: mp+330907@code.launchpad.net

Commit message

Migrate ClientSurfaces.* tests to miral APIs

Description of the change

Migrate ClientSurfaces.* tests to miral APIs

This is the first of a number of tests that rely on the legacy window management code. (I.e. include/test/mir/shell/canonical_window_manager.h)

The changes to mtf::AsyncServerRunner make it feasible to migrate the remaining tests and then ditch that legacy code.

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

PASSED: Continuous integration, rev:4254
https://mir-jenkins.ubuntu.com/job/mir-ci/3667/
Executed test runs:
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-mir/5019
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-0-fetch/5251
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-1-sourcepkg/release=artful/5239
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-1-sourcepkg/release=xenial/5239
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-1-sourcepkg/release=zesty/5239
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=clang,platform=mesa,release=artful/5062
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=clang,platform=mesa,release=artful/5062/artifact/output/*zip*/output.zip
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=clang,platform=mesa,release=zesty/5062
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=clang,platform=mesa,release=zesty/5062/artifact/output/*zip*/output.zip
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=gcc,platform=mesa,release=artful/5062
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=gcc,platform=mesa,release=artful/5062/artifact/output/*zip*/output.zip
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=gcc,platform=mesa,release=xenial/5062
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=gcc,platform=mesa,release=xenial/5062/artifact/output/*zip*/output.zip
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=gcc,platform=mesa,release=zesty/5062
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=gcc,platform=mesa,release=zesty/5062/artifact/output/*zip*/output.zip
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=cross-armhf,compiler=gcc,platform=mesa,release=artful/5062
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=cross-armhf,compiler=gcc,platform=mesa,release=artful/5062/artifact/output/*zip*/output.zip
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=cross-armhf,compiler=gcc,platform=mesa,release=zesty/5062
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=cross-armhf,compiler=gcc,platform=mesa,release=zesty/5062/artifact/output/*zip*/output.zip
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=i386,compiler=gcc,platform=mesa,release=xenial/5062
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=i386,compiler=gcc,platform=mesa,release=xenial/5062/artifact/output/*zip*/output.zip

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

review: Approve (continuous-integration)
Revision history for this message
Gerry Boland (gerboland) wrote :

LGTM

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'include/test/mir_test_framework/async_server_runner.h'
--- include/test/mir_test_framework/async_server_runner.h 2017-07-28 17:00:43 +0000
+++ include/test/mir_test_framework/async_server_runner.h 2017-09-18 11:45:09 +0000
@@ -1,5 +1,5 @@
1/*1/*
2 * Copyright © 2014 Canonical Ltd.2 * Copyright © 2014-2017 Canonical Ltd.
3 *3 *
4 * This program is free software: you can redistribute it and/or modify it4 * This program is free software: you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License version 2 or 3,5 * under the terms of the GNU General Public License version 2 or 3,
@@ -23,6 +23,7 @@
23#include "mir/test/auto_unblock_thread.h"23#include "mir/test/auto_unblock_thread.h"
2424
25#include "mir/server.h"25#include "mir/server.h"
26#include "miral/set_window_management_policy.h"
2627
27#include <condition_variable>28#include <condition_variable>
28#include <list>29#include <list>
@@ -56,10 +57,21 @@
5657
57 mir::Server server;58 mir::Server server;
5859
60 template<typename Policy, typename ...Args>
61 void override_window_management_policy(Args& ... args)
62 {
63 set_window_management_policy =
64 miral::set_window_management_policy<Policy>(args...);
65 }
66
59private:67private:
60 std::list<TemporaryEnvironmentValue> env;68 std::list<TemporaryEnvironmentValue> env;
61 mir::test::AutoJoinThread server_thread;69 mir::test::AutoJoinThread server_thread;
6270
71 // Once we migrate away from "legacy" window management stubs this can become
72 // SetWindowManagementPolicy set_window_management_policy;
73 std::function<void(mir::Server&)> set_window_management_policy;
74
63 std::mutex mutex;75 std::mutex mutex;
64 std::condition_variable started;76 std::condition_variable started;
65 bool server_running{false};77 bool server_running{false};
6678
=== added file 'include/test/mir_test_framework/canonical_window_manager_policy.h'
--- include/test/mir_test_framework/canonical_window_manager_policy.h 1970-01-01 00:00:00 +0000
+++ include/test/mir_test_framework/canonical_window_manager_policy.h 2017-09-18 11:45:09 +0000
@@ -0,0 +1,38 @@
1/*
2 * Copyright © 2017 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 2 or 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_CANONICAL_WINDOW_MANAGER_POLICY_H
20#define MIR_TEST_FRAMEWORK_CANONICAL_WINDOW_MANAGER_POLICY_H
21
22#include <miral/canonical_window_manager.h>
23
24namespace mir_test_framework
25{
26struct CanonicalWindowManagerPolicy : miral::CanonicalWindowManagerPolicy
27{
28 using miral::CanonicalWindowManagerPolicy::CanonicalWindowManagerPolicy;
29
30 bool handle_keyboard_event(MirKeyboardEvent const*) override { return false; }
31
32 bool handle_pointer_event(MirPointerEvent const*) override { return false; }
33
34 bool handle_touch_event(MirTouchEvent const*) override { return false; }
35};
36}
37
38#endif //MIR_TEST_FRAMEWORK_CANONICAL_WINDOW_MANAGER_POLICY_H
039
=== modified file 'tests/CMakeLists.txt'
--- tests/CMakeLists.txt 2017-09-07 05:58:13 +0000
+++ tests/CMakeLists.txt 2017-09-18 11:45:09 +0000
@@ -43,6 +43,7 @@
43# public headers (only public headers should be accessed by acceptance tests)43# public headers (only public headers should be accessed by acceptance tests)
44include_directories(44include_directories(
45 ${PROJECT_SOURCE_DIR}/include/platform45 ${PROJECT_SOURCE_DIR}/include/platform
46 ${PROJECT_SOURCE_DIR}/include/miral
46 ${PROJECT_SOURCE_DIR}/include/server47 ${PROJECT_SOURCE_DIR}/include/server
47 ${PROJECT_SOURCE_DIR}/include/client48 ${PROJECT_SOURCE_DIR}/include/client
48 ${PROJECT_SOURCE_DIR}/include/common49 ${PROJECT_SOURCE_DIR}/include/common
@@ -100,13 +101,16 @@
100)101)
101102
102target_link_libraries(mir-test-assist103target_link_libraries(mir-test-assist
104PUBLIC
103 mirclient105 mirclient
106 miral
104 mirserver107 mirserver
105108
106 mir-test-doubles-platform-static109 mir-test-doubles-platform-static
107 ${Boost_LIBRARIES}110 ${Boost_LIBRARIES}
108 ${GTEST_BOTH_LIBRARIES}111 ${GTEST_BOTH_LIBRARIES}
109 ${GMOCK_LIBRARY}112 ${GMOCK_LIBRARY}
113PRIVATE
110 ${GMOCK_MAIN_LIBRARY}114 ${GMOCK_MAIN_LIBRARY}
111 ${CMAKE_THREAD_LIBS_INIT} # Link in pthread.115 ${CMAKE_THREAD_LIBS_INIT} # Link in pthread.
112)116)
113117
=== modified file 'tests/acceptance-tests/test_client_surfaces.cpp'
--- tests/acceptance-tests/test_client_surfaces.cpp 2017-07-28 17:00:43 +0000
+++ tests/acceptance-tests/test_client_surfaces.cpp 2017-09-18 11:45:09 +0000
@@ -1,5 +1,5 @@
1/*1/*
2 * Copyright © 2012-2014 Canonical Ltd.2 * Copyright © 2012-2017 Canonical Ltd.
3 *3 *
4 * This program is free software: you can redistribute it and/or modify4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 or 3 as5 * it under the terms of the GNU General Public License version 2 or 3 as
@@ -19,13 +19,15 @@
19#include "mir_toolkit/mir_client_library.h"19#include "mir_toolkit/mir_client_library.h"
20#include "mir_toolkit/debug/surface.h"20#include "mir_toolkit/debug/surface.h"
2121
22#include "mir/test/doubles/mock_window_manager.h"22#include "miral/application_info.h"
2323
24#include "mir/scene/session.h"24#include "mir/scene/session.h"
25#include "mir/geometry/rectangle.h"25#include "mir/geometry/rectangle.h"
2626
27#include "mir_test_framework/canonical_window_manager_policy.h"
27#include "mir_test_framework/connected_client_headless_server.h"28#include "mir_test_framework/connected_client_headless_server.h"
28#include "mir_test_framework/any_surface.h"29#include "mir_test_framework/any_surface.h"
30
29#include "mir/test/validity_matchers.h"31#include "mir/test/validity_matchers.h"
30#include "mir/test/fake_shared.h"32#include "mir/test/fake_shared.h"
3133
@@ -36,14 +38,31 @@
36#include <mutex>38#include <mutex>
3739
38namespace mtf = mir_test_framework;40namespace mtf = mir_test_framework;
39namespace mtd = mir::test::doubles;
40namespace msh = mir::shell;41namespace msh = mir::shell;
41namespace ms = mir::scene;42namespace ms = mir::scene;
42namespace mt = mir::test;43namespace mt = mir::test;
43namespace mg = mir::geometry;44namespace mg = mir::geometry;
45using namespace testing;
4446
45namespace47namespace
46{48{
49struct MockWindowManagementPolicy : mtf::CanonicalWindowManagerPolicy
50{
51 MockWindowManagementPolicy(
52 miral::WindowManagerTools const& tools,
53 MockWindowManagementPolicy*& self) :
54 mtf::CanonicalWindowManagerPolicy(tools)
55 {
56 self = this;
57 ON_CALL(*this, place_new_window(_, _)).WillByDefault(ReturnArg<1>());
58 }
59
60 MOCK_METHOD2(place_new_window,
61 miral::WindowSpecification(miral::ApplicationInfo const& app_info, miral::WindowSpecification const& request_parameters));
62
63 MOCK_METHOD1(advise_new_window, void (miral::WindowInfo const& window_info));
64};
65
47struct ClientSurfaces : mtf::ConnectedClientHeadlessServer66struct ClientSurfaces : mtf::ConnectedClientHeadlessServer
48{67{
49 static const int max_surface_count = 5;68 static const int max_surface_count = 5;
@@ -51,14 +70,13 @@
5170
52 void SetUp() override71 void SetUp() override
53 {72 {
54 server.override_the_window_manager_builder([this](msh::FocusController*)73 override_window_management_policy<MockWindowManagementPolicy>(mock_wm_policy);
55 {74 mtf::ConnectedClientHeadlessServer::SetUp();
56 return mt::fake_shared(window_manager);75
57 });76 ASSERT_THAT(mock_wm_policy, NotNull());
58 ConnectedClientHeadlessServer::SetUp();
59 }77 }
6078
61 testing::NiceMock<mtd::MockWindowManager> window_manager;79 MockWindowManagementPolicy* mock_wm_policy = 0;
62};80};
63}81}
64#pragma GCC diagnostic push82#pragma GCC diagnostic push
@@ -351,22 +369,27 @@
351369
352 std::shared_ptr<ms::Surface> parent_surface;370 std::shared_ptr<ms::Surface> parent_surface;
353 InSequence seq;371 InSequence seq;
354 EXPECT_CALL(window_manager, add_surface(_,_,_)).WillOnce(Invoke([&parent_surface](auto session, auto params, auto builder)372 EXPECT_CALL(*mock_wm_policy, place_new_window(_, _)).Times(1);
355 {373 EXPECT_CALL(*mock_wm_policy, advise_new_window(_)).WillOnce(Invoke([&parent_surface](auto const& info)
356 auto id = builder(session, params);374 {
357 parent_surface = session->surface(id);375 parent_surface = info.window();
358 return id;376 }));
359 }));
360 EXPECT_CALL(window_manager, add_surface(_,_,_)).WillOnce(Invoke([&parent_surface, server_rect, edge_attachment](auto session, auto params, auto builder)
361 {
362 EXPECT_THAT(params.parent.lock(), Eq(parent_surface));
363 EXPECT_TRUE(params.aux_rect.is_set());
364 EXPECT_THAT(params.aux_rect.value(), Eq(server_rect));
365 EXPECT_TRUE(params.edge_attachment.is_set());
366 EXPECT_THAT(params.edge_attachment.value(), Eq(edge_attachment));
367377
368 return builder(session, params);378 EXPECT_CALL(*mock_wm_policy, place_new_window(_, _)).WillOnce(Invoke([&](auto const&, auto const& params)
369 }));379 {
380 EXPECT_TRUE(params.parent().is_set());
381 EXPECT_THAT(params.parent().value().lock(), Eq(parent_surface));
382 EXPECT_TRUE(params.aux_rect().is_set());
383 EXPECT_THAT(params.aux_rect().value(), Eq(server_rect));
384 EXPECT_TRUE(params.window_placement_gravity().is_set());
385 EXPECT_THAT(params.window_placement_gravity().value(), Eq(mir_placement_gravity_northwest));
386 EXPECT_TRUE(params.aux_rect_placement_gravity().is_set());
387 EXPECT_THAT(params.aux_rect_placement_gravity().value(), Eq(mir_placement_gravity_northeast));
388 EXPECT_TRUE(params.placement_hints().is_set());
389 EXPECT_THAT(params.placement_hints().value(), Eq(mir_placement_hints_flip_x));
390 return params;
391 }));
392 EXPECT_CALL(*mock_wm_policy, advise_new_window(_)).Times(1);
370393
371 auto window = mtf::make_any_surface(connection);394 auto window = mtf::make_any_surface(connection);
372395
373396
=== modified file 'tests/mir_test_framework/async_server_runner.cpp'
--- tests/mir_test_framework/async_server_runner.cpp 2017-08-30 11:59:02 +0000
+++ tests/mir_test_framework/async_server_runner.cpp 2017-09-18 11:45:09 +0000
@@ -1,5 +1,5 @@
1/*1/*
2 * Copyright © 2014 Canonical Ltd.2 * Copyright © 2014-2017 Canonical Ltd.
3 *3 *
4 * This program is free software: you can redistribute it and/or modify it4 * This program is free software: you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License version 2 or 3,5 * under the terms of the GNU General Public License version 2 or 3,
@@ -18,12 +18,14 @@
1818
19#include "mir_test_framework/async_server_runner.h"19#include "mir_test_framework/async_server_runner.h"
20#include "mir_test_framework/command_line_server_configuration.h"20#include "mir_test_framework/command_line_server_configuration.h"
21#include "mir_test_framework/canonical_window_manager_policy.h"
2122
22#include "mir/fd.h"23#include "mir/fd.h"
23#include "mir/main_loop.h"24#include "mir/main_loop.h"
24#include "mir/geometry/rectangle.h"25#include "mir/geometry/rectangle.h"
25#include "mir/options/option.h"26#include "mir/options/option.h"
26#include "mir/test/doubles/null_logger.h"27#include "mir/test/doubles/null_logger.h"
28#include <miral/set_window_management_policy.h>
27#include <mir/shell/canonical_window_manager.h>29#include <mir/shell/canonical_window_manager.h>
2830
29#include <boost/throw_exception.hpp>31#include <boost/throw_exception.hpp>
@@ -42,7 +44,8 @@
42std::chrono::seconds const timeout{20};44std::chrono::seconds const timeout{20};
43}45}
4446
45mtf::AsyncServerRunner::AsyncServerRunner()47mtf::AsyncServerRunner::AsyncServerRunner() :
48 set_window_management_policy{[](auto&){}}
46{49{
47 configure_from_commandline(server);50 configure_from_commandline(server);
4851
@@ -56,6 +59,9 @@
5659
57 return result;60 return result;
58 });61 });
62 // TODO This is here to support tests that rely on the legacy window management code
63 // once they go, then we can set set_window_management_policy appropriately, kill this
64 // and remove msh::CanonicalWindowManager
59 server.override_the_window_manager_builder([this](msh::FocusController* focus_controller)65 server.override_the_window_manager_builder([this](msh::FocusController* focus_controller)
60 {66 {
61#pragma GCC diagnostic push67#pragma GCC diagnostic push
@@ -74,6 +80,8 @@
7480
75void mtf::AsyncServerRunner::start_server()81void mtf::AsyncServerRunner::start_server()
76{82{
83 set_window_management_policy(server);
84
77 server.add_init_callback([&]85 server.add_init_callback([&]
78 {86 {
79 auto const main_loop = server.the_main_loop();87 auto const main_loop = server.the_main_loop();
8088
=== modified file 'tests/performance-tests/CMakeLists.txt'
--- tests/performance-tests/CMakeLists.txt 2017-05-08 03:04:26 +0000
+++ tests/performance-tests/CMakeLists.txt 2017-09-18 11:45:09 +0000
@@ -17,11 +17,7 @@
17)17)
18add_dependencies(mir_glmark2_performance_test GMock)18add_dependencies(mir_glmark2_performance_test GMock)
19target_link_libraries(mir_glmark2_performance_test19target_link_libraries(mir_glmark2_performance_test
20 mir-test-static20 mir-test-assist
21 mir-test-framework-static
22 mir-test-doubles-static
23 mirserver
24 ${GTEST_BOTH_LIBRARIES}
25)21)
2622
27add_library(mir_system_performance_test STATIC23add_library(mir_system_performance_test STATIC
@@ -40,10 +36,6 @@
40 test_client_startup.cpp36 test_client_startup.cpp
41)37)
42target_link_libraries(mir_client_startup_performance_test38target_link_libraries(mir_client_startup_performance_test
43 mir-test-static39 mir-test-assist
44 mir-test-framework-static
45 mir-test-doubles-static
46 mirserver
47 ${GTEST_BOTH_LIBRARIES}
48)40)
4941

Subscribers

People subscribed via source and target branches