Mir

Merge lp:~afrantzis/mir/remove-set-gbm-device-nested into lp:mir

Proposed by Alexandros Frantzis
Status: Merged
Approved by: Alexandros Frantzis
Approved revision: no longer in the source branch.
Merged at revision: 2298
Proposed branch: lp:~afrantzis/mir/remove-set-gbm-device-nested
Merge into: lp:mir
Prerequisite: lp:~afrantzis/mir/platform-operation-set-gbm-device
Diff against target: 623 lines (+162/-105)
17 files modified
src/client/mir_connection_api.cpp (+11/-6)
src/include/platform/mir/graphics/nested_context.h (+0/-1)
src/platforms/mesa/client/client_platform.cpp (+6/-5)
src/platforms/mesa/server/guest_platform.cpp (+48/-19)
src/platforms/mesa/server/guest_platform.h (+1/-1)
src/platforms/mesa/server/ipc_operations.cpp (+10/-9)
src/platforms/mesa/server/nested_authentication.cpp (+10/-9)
src/server/frontend/session_mediator.cpp (+8/-7)
src/server/graphics/nested/mir_client_host_connection.cpp (+0/-10)
src/server/graphics/nested/mir_client_host_connection.h (+0/-1)
tests/include/mir_test_doubles/mock_nested_context.h (+15/-1)
tests/include/mir_test_doubles/stub_host_connection.h (+0/-1)
tests/integration-tests/test_drm_auth_magic.cpp (+5/-3)
tests/unit-tests/client/mesa/test_client_platform.cpp (+12/-5)
tests/unit-tests/graphics/mesa/test_guest_platform.cpp (+22/-1)
tests/unit-tests/graphics/mesa/test_ipc_operations.cpp (+5/-3)
tests/unit-tests/graphics/mesa/test_nested_authentication.cpp (+9/-23)
To merge this branch: bzr merge lp:~afrantzis/mir/remove-set-gbm-device-nested
Reviewer Review Type Date Requested Status
PS Jenkins bot (community) continuous-integration Approve
Kevin DuBois (community) Approve
Alan Griffiths Approve
Daniel van Vugt Pending
Review via email: mp+248337@code.launchpad.net

This proposal supersedes a proposal from 2015-02-02.

Commit message

nested: Replace drm_set_gbm_device calls with platform_operation calls

Description of the change

nested: Replace drm_set_gbm_device calls with platform_operation calls

This MP removes the last instance of a platform-dependent API from the nested server.

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote : Posted in a previous version of this proposal
review: Approve (continuous-integration)
Revision history for this message
Daniel van Vugt (vanvugt) wrote : Posted in a previous version of this proposal

Targeting the wrong branch now. Somehow!?

review: Needs Resubmitting
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 :

244 + auto request_ptr = reinterpret_cast<MirMesaSetGBMDeviceRequest*>(
245 + request_msg.data.data());

Here and elsewhere you're reinterpret_casting data allocated with a uint8_t alignment to structure that needs stricter alignment (e.g. int or type*). That isn't safe (and even on processors where it is "safe" can be very inefficient.

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

Failure seems unrelated. Rebuilding.

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

> 244 + auto request_ptr = reinterpret_cast<MirMesaSetGBMDeviceRequest*>(
> 245 + request_msg.data.data());
>
> Here and elsewhere you're reinterpret_casting data allocated with a uint8_t alignment to structure > that needs stricter alignment (e.g. int or type*). That isn't safe (and even on processors where it > is "safe" can be very inefficient.

Fixed. I also fixed instances of this issue introduced by earlier branches.

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

LGTM

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

lgtm too

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

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'src/client/mir_connection_api.cpp'
--- src/client/mir_connection_api.cpp 2015-02-03 18:51:02 +0000
+++ src/client/mir_connection_api.cpp 2015-02-04 15:02:31 +0000
@@ -346,9 +346,12 @@
346 static_cast<AuthMagicPlatformOperationContext*>(context)};346 static_cast<AuthMagicPlatformOperationContext*>(context)};
347347
348 auto response_data = mir_platform_message_get_data(response_msg.get());348 auto response_data = mir_platform_message_get_data(response_msg.get());
349 auto auth_response = reinterpret_cast<MirMesaAuthMagicResponse const*>(response_data.data);349 MirMesaAuthMagicResponse auth_response{-1};
350350
351 auth_magic_context->callback(auth_response->status, auth_magic_context->context);351 if (response_data.size == sizeof(auth_response))
352 std::memcpy(&auth_response, response_data.data, response_data.size);
353
354 auth_magic_context->callback(auth_response.status, auth_magic_context->context);
352}355}
353356
354void assign_set_gbm_device_status(357void assign_set_gbm_device_status(
@@ -359,11 +362,13 @@
359 &mir_platform_message_release);362 &mir_platform_message_release);
360363
361 auto const response_data = mir_platform_message_get_data(response_msg.get());364 auto const response_data = mir_platform_message_get_data(response_msg.get());
362 auto const set_gbm_device_response_ptr =365 MirMesaSetGBMDeviceResponse set_gbm_device_response{-1};
363 reinterpret_cast<MirMesaSetGBMDeviceResponse const*>(response_data.data);366
367 if (response_data.size == sizeof(set_gbm_device_response))
368 std::memcpy(&set_gbm_device_response, response_data.data, response_data.size);
364369
365 auto status_ptr = static_cast<int*>(context);370 auto status_ptr = static_cast<int*>(context);
366 *status_ptr = set_gbm_device_response_ptr->status;371 *status_ptr = set_gbm_device_response.status;
367}372}
368373
369}374}
370375
=== modified file 'src/include/platform/mir/graphics/nested_context.h'
--- src/include/platform/mir/graphics/nested_context.h 2015-02-02 12:18:18 +0000
+++ src/include/platform/mir/graphics/nested_context.h 2015-02-04 15:02:31 +0000
@@ -35,7 +35,6 @@
35 virtual ~NestedContext() = default;35 virtual ~NestedContext() = default;
3636
37 virtual std::vector<int> platform_fd_items() = 0;37 virtual std::vector<int> platform_fd_items() = 0;
38 virtual void drm_set_gbm_device(struct gbm_device* dev) = 0;
39 virtual PlatformOperationMessage platform_operation(38 virtual PlatformOperationMessage platform_operation(
40 unsigned int op, PlatformOperationMessage const& request) = 0;39 unsigned int op, PlatformOperationMessage const& request) = 0;
4140
4241
=== modified file 'src/platforms/mesa/client/client_platform.cpp'
--- src/platforms/mesa/client/client_platform.cpp 2015-02-03 15:07:44 +0000
+++ src/platforms/mesa/client/client_platform.cpp 2015-02-04 15:02:31 +0000
@@ -136,14 +136,15 @@
136 MirPlatformMessage const* msg)136 MirPlatformMessage const* msg)
137{137{
138 auto const op = mir_platform_message_get_opcode(msg);138 auto const op = mir_platform_message_get_opcode(msg);
139 auto const msg_data = mir_platform_message_get_data(msg);
139140
140 if (op == MirMesaPlatformOperation::set_gbm_device)141 if (op == MirMesaPlatformOperation::set_gbm_device &&
142 msg_data.size == sizeof(MirMesaSetGBMDeviceRequest))
141 {143 {
142 auto const msg_data = mir_platform_message_get_data(msg);144 MirMesaSetGBMDeviceRequest set_gbm_device_request{nullptr};
143 auto const set_gbm_device_request_ptr =145 std::memcpy(&set_gbm_device_request, msg_data.data, msg_data.size);
144 reinterpret_cast<MirMesaSetGBMDeviceRequest const*>(msg_data.data);
145146
146 gbm_dev = set_gbm_device_request_ptr->device;147 gbm_dev = set_gbm_device_request.device;
147148
148 static int const success{0};149 static int const success{0};
149 MirMesaSetGBMDeviceResponse const response{success};150 MirMesaSetGBMDeviceResponse const response{success};
150151
=== modified file 'src/platforms/mesa/server/guest_platform.cpp'
--- src/platforms/mesa/server/guest_platform.cpp 2015-01-22 09:00:14 +0000
+++ src/platforms/mesa/server/guest_platform.cpp 2015-02-04 15:02:31 +0000
@@ -19,32 +19,67 @@
19 */19 */
2020
21#include "guest_platform.h"21#include "guest_platform.h"
2222#include "nested_authentication.h"
23#include "ipc_operations.h"
23#include "buffer_allocator.h"24#include "buffer_allocator.h"
24#include "mir/graphics/buffer_ipc_message.h"25
25#include "mir/graphics/platform_ipc_package.h"
26#include "mir/graphics/nested_context.h"26#include "mir/graphics/nested_context.h"
2727#include "mir/graphics/platform_operation_message.h"
28#include "nested_authentication.h"28#include "mir_toolkit/mesa/platform_operation.h"
29
30#include "ipc_operations.h"
3129
32#include <boost/exception/errinfo_errno.hpp>30#include <boost/exception/errinfo_errno.hpp>
33#include <boost/throw_exception.hpp>31#include <boost/throw_exception.hpp>
3432
35#include <mutex>33#include <mutex>
36#include <stdexcept>34#include <stdexcept>
35#include <cstring>
3736
38namespace mg = mir::graphics;37namespace mg = mir::graphics;
39namespace mgm = mg::mesa;38namespace mgm = mg::mesa;
4039
41mgm::GuestPlatform::GuestPlatform(std::shared_ptr<NestedContext> const& nested_context_arg)40namespace
42{41{
43 //TODO: a bit of round-about initialization to clean up here42
44 nested_context = nested_context_arg;43void set_guest_gbm_device(mg::NestedContext& nested_context, gbm_device* gbm_dev)
45 auto fds = nested_context->platform_fd_items();44{
45 MirMesaSetGBMDeviceRequest const request{gbm_dev};
46 mg::PlatformOperationMessage request_msg;
47 request_msg.data.resize(sizeof(MirMesaSetGBMDeviceRequest));
48 std::memcpy(request_msg.data.data(), &request, sizeof(request));
49
50 auto const response_msg = nested_context.platform_operation(
51 MirMesaPlatformOperation::set_gbm_device,
52 request_msg);
53
54 if (response_msg.data.size() == sizeof(MirMesaSetGBMDeviceResponse))
55 {
56 static int const success{0};
57 MirMesaSetGBMDeviceResponse response{-1};
58 std::memcpy(&response, response_msg.data.data(), response_msg.data.size());
59 if (response.status != success)
60 {
61 std::string const msg{"Nested Mir failed to set the gbm device."};
62 BOOST_THROW_EXCEPTION(
63 boost::enable_error_info(std::runtime_error(msg))
64 << boost::errinfo_errno(response.status));
65 }
66 }
67 else
68 {
69 std::string const msg{"Nested Mir failed to set the gbm device: Invalid response."};
70 BOOST_THROW_EXCEPTION(std::runtime_error(msg));
71 }
72}
73
74}
75
76mgm::GuestPlatform::GuestPlatform(
77 std::shared_ptr<NestedContext> const& nested_context)
78 : nested_context{nested_context}
79{
80 auto const fds = nested_context->platform_fd_items();
46 gbm.setup(fds.at(0));81 gbm.setup(fds.at(0));
47 nested_context->drm_set_gbm_device(gbm.device);82 set_guest_gbm_device(*nested_context, gbm.device);
48 ipc_ops = std::make_shared<mgm::IpcOperations>(83 ipc_ops = std::make_shared<mgm::IpcOperations>(
49 std::make_shared<mgm::NestedAuthentication>(nested_context)); 84 std::make_shared<mgm::NestedAuthentication>(nested_context));
50}85}
@@ -61,12 +96,6 @@
61 return std::make_shared<mgm::GuestPlatform>(nested_context);96 return std::make_shared<mgm::GuestPlatform>(nested_context);
62}97}
6398
64namespace
65{
66std::shared_ptr<mgm::InternalNativeDisplay> native_display = nullptr;
67std::mutex native_display_guard;
68}
69
70std::shared_ptr<mg::PlatformIpcOperations> mgm::GuestPlatform::make_ipc_operations() const99std::shared_ptr<mg::PlatformIpcOperations> mgm::GuestPlatform::make_ipc_operations() const
71{100{
72 return ipc_ops;101 return ipc_ops;
73102
=== modified file 'src/platforms/mesa/server/guest_platform.h'
--- src/platforms/mesa/server/guest_platform.h 2015-01-22 09:00:14 +0000
+++ src/platforms/mesa/server/guest_platform.h 2015-02-04 15:02:31 +0000
@@ -48,7 +48,7 @@
48 EGLNativeDisplayType egl_native_display() const override;48 EGLNativeDisplayType egl_native_display() const override;
4949
50private:50private:
51 std::shared_ptr<NestedContext> nested_context;51 std::shared_ptr<NestedContext> const nested_context;
52 helpers::GBMHelper gbm;52 helpers::GBMHelper gbm;
53 std::shared_ptr<PlatformIpcOperations> ipc_ops;53 std::shared_ptr<PlatformIpcOperations> ipc_ops;
54};54};
5555
=== modified file 'src/platforms/mesa/server/ipc_operations.cpp'
--- src/platforms/mesa/server/ipc_operations.cpp 2015-02-02 12:18:18 +0000
+++ src/platforms/mesa/server/ipc_operations.cpp 2015-02-04 15:02:31 +0000
@@ -31,6 +31,8 @@
31#include <boost/exception/get_error_info.hpp>31#include <boost/exception/get_error_info.hpp>
32#include <boost/exception/errinfo_errno.hpp>32#include <boost/exception/errinfo_errno.hpp>
3333
34#include <cstring>
35
34namespace mg = mir::graphics;36namespace mg = mir::graphics;
35namespace mgm = mir::graphics::mesa;37namespace mgm = mir::graphics::mesa;
3638
@@ -89,8 +91,7 @@
89 MirMesaAuthMagicRequest auth_magic_request;91 MirMesaAuthMagicRequest auth_magic_request;
90 if (request.data.size() == sizeof(auth_magic_request))92 if (request.data.size() == sizeof(auth_magic_request))
91 {93 {
92 auth_magic_request =94 std::memcpy(&auth_magic_request, request.data.data(), request.data.size());
93 *reinterpret_cast<decltype(auth_magic_request) const*>(request.data.data());
94 }95 }
95 else96 else
96 {97 {
@@ -98,27 +99,27 @@
98 std::runtime_error("Invalid request message for auth_magic platform operation"));99 std::runtime_error("Invalid request message for auth_magic platform operation"));
99 }100 }
100101
101 mg::PlatformOperationMessage response;102 MirMesaAuthMagicResponse auth_magic_response{-1};
102 response.data.resize(sizeof(MirMesaAuthMagicResponse));
103 auto const auth_magic_response_ptr =
104 reinterpret_cast<MirMesaAuthMagicResponse*>(response.data.data());
105103
106 try104 try
107 {105 {
108 drm_auth->auth_magic(auth_magic_request.magic);106 drm_auth->auth_magic(auth_magic_request.magic);
109 auth_magic_response_ptr->status = 0;107 auth_magic_response.status = 0;
110 }108 }
111 catch (std::exception const& e)109 catch (std::exception const& e)
112 {110 {
113 auto errno_ptr = boost::get_error_info<boost::errinfo_errno>(e);111 auto errno_ptr = boost::get_error_info<boost::errinfo_errno>(e);
114112
115 if (errno_ptr != nullptr)113 if (errno_ptr != nullptr)
116 auth_magic_response_ptr->status = *errno_ptr;114 auth_magic_response.status = *errno_ptr;
117 else115 else
118 throw;116 throw;
119 }117 }
120118
121 return response;119 mg::PlatformOperationMessage response_msg;
120 response_msg.data.resize(sizeof(auth_magic_response));
121 std::memcpy(response_msg.data.data(), &auth_magic_response, sizeof(auth_magic_response));
122 return response_msg;
122 }123 }
123 else if (op == MirMesaPlatformOperation::auth_fd)124 else if (op == MirMesaPlatformOperation::auth_fd)
124 {125 {
125126
=== modified file 'src/platforms/mesa/server/nested_authentication.cpp'
--- src/platforms/mesa/server/nested_authentication.cpp 2015-02-02 12:18:18 +0000
+++ src/platforms/mesa/server/nested_authentication.cpp 2015-02-04 15:02:31 +0000
@@ -25,6 +25,8 @@
25#include <boost/exception/errinfo_errno.hpp>25#include <boost/exception/errinfo_errno.hpp>
26#include <boost/throw_exception.hpp>26#include <boost/throw_exception.hpp>
2727
28#include <cstring>
29
28namespace mg = mir::graphics;30namespace mg = mir::graphics;
29namespace mgm = mir::graphics::mesa;31namespace mgm = mir::graphics::mesa;
3032
@@ -33,12 +35,11 @@
3335
34mg::PlatformOperationMessage make_auth_magic_request_message(drm_magic_t magic)36mg::PlatformOperationMessage make_auth_magic_request_message(drm_magic_t magic)
35{37{
36 mg::PlatformOperationMessage request;38 MirMesaAuthMagicRequest const request{magic};
37 request.data.resize(sizeof(MirMesaAuthMagicRequest));39 mg::PlatformOperationMessage request_msg;
38 auto auth_magic_request_ptr =40 request_msg.data.resize(sizeof(request));
39 reinterpret_cast<MirMesaAuthMagicRequest*>(request.data.data());41 std::memcpy(request_msg.data.data(), &request, sizeof(request));
40 auth_magic_request_ptr->magic = magic;42 return request_msg;
41 return request;
42}43}
4344
44MirMesaAuthMagicResponse auth_magic_response_from_message(45MirMesaAuthMagicResponse auth_magic_response_from_message(
@@ -46,10 +47,10 @@
46{47{
47 if (msg.data.size() == sizeof(MirMesaAuthMagicResponse))48 if (msg.data.size() == sizeof(MirMesaAuthMagicResponse))
48 {49 {
49 auto auth_magic_response_ptr =50 MirMesaAuthMagicResponse response{-1};
50 reinterpret_cast<MirMesaAuthMagicResponse const*>(msg.data.data());51 std::memcpy(&response, msg.data.data(), msg.data.size());
5152
52 return *auth_magic_response_ptr;53 return response;
53 }54 }
5455
55 BOOST_THROW_EXCEPTION(56 BOOST_THROW_EXCEPTION(
5657
=== modified file 'src/server/frontend/session_mediator.cpp'
--- src/server/frontend/session_mediator.cpp 2015-02-02 12:18:18 +0000
+++ src/server/frontend/session_mediator.cpp 2015-02-04 15:02:31 +0000
@@ -61,6 +61,7 @@
6161
62#include <mutex>62#include <mutex>
63#include <functional>63#include <functional>
64#include <cstring>
6465
65namespace ms = mir::scene;66namespace ms = mir::scene;
66namespace mf = mir::frontend;67namespace mf = mir::frontend;
@@ -636,18 +637,18 @@
636637
637 auto const magic = request->magic();638 auto const magic = request->magic();
638639
640 MirMesaAuthMagicRequest const auth_magic_request{magic};
639 mg::PlatformOperationMessage platform_request;641 mg::PlatformOperationMessage platform_request;
640 platform_request.data.resize(sizeof(MirMesaAuthMagicRequest));642 platform_request.data.resize(sizeof(auth_magic_request));
641 auto const auth_magic_request_ptr =643 std::memcpy(platform_request.data.data(), &auth_magic_request, sizeof(auth_magic_request));
642 reinterpret_cast<MirMesaAuthMagicRequest*>(platform_request.data.data());
643 *auth_magic_request_ptr = MirMesaAuthMagicRequest{magic};
644644
645 auto const platform_response = ipc_operations->platform_operation(645 auto const platform_response = ipc_operations->platform_operation(
646 MirMesaPlatformOperation::auth_magic, platform_request);646 MirMesaPlatformOperation::auth_magic, platform_request);
647647
648 auto const auth_magic_response_ptr =648 MirMesaAuthMagicResponse auth_magic_response{-1};
649 reinterpret_cast<MirMesaAuthMagicResponse const*>(platform_response.data.data());649 std::memcpy(&auth_magic_response, platform_response.data.data(),
650 response->set_status_code(auth_magic_response_ptr->status);650 platform_response.data.size());
651 response->set_status_code(auth_magic_response.status);
651652
652 done->Run();653 done->Run();
653}654}
654655
=== modified file 'src/server/graphics/nested/mir_client_host_connection.cpp'
--- src/server/graphics/nested/mir_client_host_connection.cpp 2015-02-03 18:51:02 +0000
+++ src/server/graphics/nested/mir_client_host_connection.cpp 2015-02-04 15:02:31 +0000
@@ -18,7 +18,6 @@
1818
19#include "mir_client_host_connection.h"19#include "mir_client_host_connection.h"
20#include "mir_toolkit/mir_client_library.h"20#include "mir_toolkit/mir_client_library.h"
21#include "mir_toolkit/mir_client_library_drm.h"
22#include "mir/raii.h"21#include "mir/raii.h"
23#include "mir/graphics/platform_operation_message.h"22#include "mir/graphics/platform_operation_message.h"
2423
@@ -163,15 +162,6 @@
163 mir_connection, surface_parameters);162 mir_connection, surface_parameters);
164}163}
165164
166void mgn::MirClientHostConnection::drm_set_gbm_device(struct gbm_device* dev)
167{
168 if (!mir_connection_drm_set_gbm_device(mir_connection, dev))
169 {
170 std::string const msg("Nested Mir failed to set the gbm device");
171 BOOST_THROW_EXCEPTION(std::runtime_error(msg));
172 }
173}
174
175mg::PlatformOperationMessage mgn::MirClientHostConnection::platform_operation(165mg::PlatformOperationMessage mgn::MirClientHostConnection::platform_operation(
176 unsigned int op, mg::PlatformOperationMessage const& request)166 unsigned int op, mg::PlatformOperationMessage const& request)
177{167{
178168
=== modified file 'src/server/graphics/nested/mir_client_host_connection.h'
--- src/server/graphics/nested/mir_client_host_connection.h 2015-02-02 12:18:18 +0000
+++ src/server/graphics/nested/mir_client_host_connection.h 2015-02-04 15:02:31 +0000
@@ -48,7 +48,6 @@
48 void set_display_config_change_callback(std::function<void()> const& cb) override;48 void set_display_config_change_callback(std::function<void()> const& cb) override;
49 void apply_display_config(MirDisplayConfiguration&) override;49 void apply_display_config(MirDisplayConfiguration&) override;
5050
51 void drm_set_gbm_device(struct gbm_device* dev) override;
52 virtual PlatformOperationMessage platform_operation(51 virtual PlatformOperationMessage platform_operation(
53 unsigned int op, PlatformOperationMessage const& request) override;52 unsigned int op, PlatformOperationMessage const& request) override;
5453
5554
=== modified file 'tests/include/mir_test_doubles/mock_nested_context.h'
--- tests/include/mir_test_doubles/mock_nested_context.h 2015-01-26 15:53:18 +0000
+++ tests/include/mir_test_doubles/mock_nested_context.h 2015-02-04 15:02:31 +0000
@@ -24,6 +24,21 @@
2424
25namespace mir25namespace mir
26{26{
27namespace graphics
28{
29inline bool operator==(PlatformOperationMessage const& msg1,
30 PlatformOperationMessage const& msg2)
31{
32 return msg1.data == msg2.data && msg1.fds == msg2.fds;
33}
34
35inline bool operator!=(PlatformOperationMessage const& msg1,
36 PlatformOperationMessage const& msg2)
37{
38 return !(msg1 == msg2);
39}
40}
41
27namespace test42namespace test
28{43{
29namespace doubles44namespace doubles
@@ -33,7 +48,6 @@
33{48{
34 MOCK_METHOD0(platform_fd_items, std::vector<int>());49 MOCK_METHOD0(platform_fd_items, std::vector<int>());
35 MOCK_METHOD1(drm_auth_magic, void(int magic));50 MOCK_METHOD1(drm_auth_magic, void(int magic));
36 MOCK_METHOD1(drm_set_gbm_device, void(struct gbm_device* dev));
37 MOCK_METHOD2(platform_operation, graphics::PlatformOperationMessage(51 MOCK_METHOD2(platform_operation, graphics::PlatformOperationMessage(
38 unsigned int, graphics::PlatformOperationMessage const&));52 unsigned int, graphics::PlatformOperationMessage const&));
39};53};
4054
=== modified file 'tests/include/mir_test_doubles/stub_host_connection.h'
--- tests/include/mir_test_doubles/stub_host_connection.h 2015-01-26 15:53:18 +0000
+++ tests/include/mir_test_doubles/stub_host_connection.h 2015-02-04 15:02:31 +0000
@@ -61,7 +61,6 @@
61 return std::make_shared<NullHostSurface>();61 return std::make_shared<NullHostSurface>();
62 }62 }
6363
64 void drm_set_gbm_device(struct gbm_device*) override {}
65 graphics::PlatformOperationMessage platform_operation(64 graphics::PlatformOperationMessage platform_operation(
66 unsigned int, graphics::PlatformOperationMessage const&) override65 unsigned int, graphics::PlatformOperationMessage const&) override
67 {66 {
6867
=== modified file 'tests/integration-tests/test_drm_auth_magic.cpp'
--- tests/integration-tests/test_drm_auth_magic.cpp 2015-02-02 12:18:18 +0000
+++ tests/integration-tests/test_drm_auth_magic.cpp 2015-02-04 15:02:31 +0000
@@ -35,6 +35,8 @@
35#include <gmock/gmock.h>35#include <gmock/gmock.h>
36#include <gtest/gtest.h>36#include <gtest/gtest.h>
3737
38#include <cstring>
39
38namespace mg = mir::graphics;40namespace mg = mir::graphics;
39namespace mc = mir::compositor;41namespace mc = mir::compositor;
40namespace geom = mir::geometry;42namespace geom = mir::geometry;
@@ -102,9 +104,9 @@
102 if (!platform)104 if (!platform)
103 {105 {
104 mg::PlatformOperationMessage pkg;106 mg::PlatformOperationMessage pkg;
105 pkg.data.resize(sizeof(MirMesaAuthMagicResponse));107 pkg.data.resize(sizeof(auth_magic_response));
106 *(reinterpret_cast<MirMesaAuthMagicResponse*>(pkg.data.data())) =108 std::memcpy(pkg.data.data(), &auth_magic_response,
107 auth_magic_response;109 sizeof(auth_magic_response));
108110
109 auto ipc_ops = std::make_shared<NiceMock<MockAuthenticatingIpcOps>>();111 auto ipc_ops = std::make_shared<NiceMock<MockAuthenticatingIpcOps>>();
110 EXPECT_CALL(*ipc_ops, platform_operation(_,_))112 EXPECT_CALL(*ipc_ops, platform_operation(_,_))
111113
=== modified file 'tests/unit-tests/client/mesa/test_client_platform.cpp'
--- tests/unit-tests/client/mesa/test_client_platform.cpp 2015-02-03 15:07:44 +0000
+++ tests/unit-tests/client/mesa/test_client_platform.cpp 2015-02-04 15:02:31 +0000
@@ -29,6 +29,8 @@
29#include <gtest/gtest.h>29#include <gtest/gtest.h>
30#include <gmock/gmock.h>30#include <gmock/gmock.h>
3131
32#include <cstring>
33
32namespace mcl = mir::client;34namespace mcl = mir::client;
33namespace mclm = mir::client::mesa;35namespace mclm = mir::client::mesa;
34namespace mtf = mir_test_framework;36namespace mtf = mir_test_framework;
@@ -95,9 +97,10 @@
95 ASSERT_THAT(response_msg, NotNull());97 ASSERT_THAT(response_msg, NotNull());
96 auto const response_data = mir_platform_message_get_data(response_msg.get());98 auto const response_data = mir_platform_message_get_data(response_msg.get());
97 ASSERT_THAT(response_data.size, Eq(sizeof(MirMesaSetGBMDeviceResponse)));99 ASSERT_THAT(response_data.size, Eq(sizeof(MirMesaSetGBMDeviceResponse)));
98 auto const response_ptr =100
99 reinterpret_cast<MirMesaSetGBMDeviceResponse const*>(response_data.data);101 MirMesaSetGBMDeviceResponse response{-1};
100 EXPECT_THAT(response_ptr->status, Eq(success));102 std::memcpy(&response, response_data.data, response_data.size);
103 EXPECT_THAT(response.status, Eq(success));
101}104}
102105
103TEST_F(MesaClientPlatformTest, appends_gbm_device_to_platform_package)106TEST_F(MesaClientPlatformTest, appends_gbm_device_to_platform_package)
@@ -115,6 +118,10 @@
115118
116 platform->populate(pkg);119 platform->populate(pkg);
117 EXPECT_THAT(pkg.data_items, Eq(previous_data_count + (sizeof(gbm_dev_dummy) / sizeof(int))));120 EXPECT_THAT(pkg.data_items, Eq(previous_data_count + (sizeof(gbm_dev_dummy) / sizeof(int))));
118 EXPECT_THAT(reinterpret_cast<struct gbm_device*>(pkg.data[previous_data_count]),121
119 Eq(gbm_dev_dummy));122 gbm_device* device_in_package{nullptr};
123 std::memcpy(&device_in_package, &pkg.data[previous_data_count],
124 sizeof(device_in_package));
125
126 EXPECT_THAT(device_in_package, Eq(gbm_dev_dummy));
120}127}
121128
=== modified file 'tests/unit-tests/graphics/mesa/test_guest_platform.cpp'
--- tests/unit-tests/graphics/mesa/test_guest_platform.cpp 2015-02-02 12:18:18 +0000
+++ tests/unit-tests/graphics/mesa/test_guest_platform.cpp 2015-02-04 15:02:31 +0000
@@ -33,6 +33,8 @@
33#include <gtest/gtest.h>33#include <gtest/gtest.h>
34#include <gmock/gmock.h>34#include <gmock/gmock.h>
3535
36#include <cstring>
37
36namespace mg = mir::graphics;38namespace mg = mir::graphics;
37namespace mgm = mir::graphics::mesa;39namespace mgm = mir::graphics::mesa;
38namespace mt = mir::test;40namespace mt = mir::test;
@@ -49,8 +51,17 @@
49 {51 {
50 using namespace testing;52 using namespace testing;
5153
54 MirMesaSetGBMDeviceResponse const response_success{0};
55 mg::PlatformOperationMessage set_gbm_device_success_msg;
56 set_gbm_device_success_msg.data.resize(sizeof(response_success));
57 std::memcpy(set_gbm_device_success_msg.data.data(),
58 &response_success, sizeof(response_success));
59
52 ON_CALL(mock_nested_context, platform_fd_items())60 ON_CALL(mock_nested_context, platform_fd_items())
53 .WillByDefault(Return(std::vector<int>{mock_drm.fake_drm.fd()}));61 .WillByDefault(Return(std::vector<int>{mock_drm.fake_drm.fd()}));
62 ON_CALL(mock_nested_context,
63 platform_operation(MirMesaPlatformOperation::set_gbm_device, _))
64 .WillByDefault(Return(set_gbm_device_success_msg));
54 }65 }
5566
56protected:67protected:
@@ -69,6 +80,8 @@
69 mg::PlatformOperationMessage auth_fd_response{{},{auth_fd}};80 mg::PlatformOperationMessage auth_fd_response{{},{auth_fd}};
7081
71 EXPECT_CALL(mock_nested_context,82 EXPECT_CALL(mock_nested_context,
83 platform_operation(MirMesaPlatformOperation::set_gbm_device, _));
84 EXPECT_CALL(mock_nested_context,
72 platform_operation(MirMesaPlatformOperation::auth_fd, _))85 platform_operation(MirMesaPlatformOperation::auth_fd, _))
73 .WillOnce(Return(auth_fd_response));86 .WillOnce(Return(auth_fd_response));
7487
@@ -79,6 +92,14 @@
7992
80TEST_F(MesaGuestPlatformTest, sets_gbm_device_during_initialization)93TEST_F(MesaGuestPlatformTest, sets_gbm_device_during_initialization)
81{94{
82 EXPECT_CALL(mock_nested_context, drm_set_gbm_device(mock_gbm.fake_gbm.device));95 MirMesaSetGBMDeviceRequest const request{mock_gbm.fake_gbm.device};
96 mg::PlatformOperationMessage request_msg;
97 request_msg.data.resize(sizeof(request));
98 std::memcpy(request_msg.data.data(), &request, sizeof(request));
99
100 EXPECT_CALL(mock_nested_context,
101 platform_operation(MirMesaPlatformOperation::set_gbm_device,
102 request_msg));
103
83 mgm::GuestPlatform native(mt::fake_shared(mock_nested_context));104 mgm::GuestPlatform native(mt::fake_shared(mock_nested_context));
84}105}
85106
=== modified file 'tests/unit-tests/graphics/mesa/test_ipc_operations.cpp'
--- tests/unit-tests/graphics/mesa/test_ipc_operations.cpp 2015-02-02 12:18:18 +0000
+++ tests/unit-tests/graphics/mesa/test_ipc_operations.cpp 2015-02-04 15:02:31 +0000
@@ -29,6 +29,8 @@
29#include "mir_test_doubles/mock_drm.h"29#include "mir_test_doubles/mock_drm.h"
30#include <gtest/gtest.h>30#include <gtest/gtest.h>
3131
32#include <cstring>
33
32namespace mg = mir::graphics;34namespace mg = mir::graphics;
33namespace mt = mir::test;35namespace mt = mir::test;
34namespace mtd = mir::test::doubles;36namespace mtd = mir::test::doubles;
@@ -101,14 +103,14 @@
101103
102 mg::PlatformOperationMessage request_msg;104 mg::PlatformOperationMessage request_msg;
103 request_msg.data.resize(sizeof(request));105 request_msg.data.resize(sizeof(request));
104 *(reinterpret_cast<decltype(request)*>(request_msg.data.data())) = request;106 std::memcpy(request_msg.data.data(), &request, sizeof(request));
105107
106 auto response_msg = ipc_ops.platform_operation(108 auto response_msg = ipc_ops.platform_operation(
107 MirMesaPlatformOperation::auth_magic, request_msg);109 MirMesaPlatformOperation::auth_magic, request_msg);
108110
109 MirMesaAuthMagicResponse response;111 MirMesaAuthMagicResponse response{-1};
110 ASSERT_THAT(response_msg.data.size(), Eq(sizeof(response)));112 ASSERT_THAT(response_msg.data.size(), Eq(sizeof(response)));
111 response = *(reinterpret_cast<decltype(response)*>(response_msg.data.data()));113 std::memcpy(&response, response_msg.data.data(), response_msg.data.size());
112 EXPECT_THAT(response.status, Eq(0));114 EXPECT_THAT(response.status, Eq(0));
113}115}
114116
115117
=== modified file 'tests/unit-tests/graphics/mesa/test_nested_authentication.cpp'
--- tests/unit-tests/graphics/mesa/test_nested_authentication.cpp 2015-02-02 12:18:18 +0000
+++ tests/unit-tests/graphics/mesa/test_nested_authentication.cpp 2015-02-04 15:02:31 +0000
@@ -25,6 +25,8 @@
25#include "mir_test/fake_shared.h"25#include "mir_test/fake_shared.h"
26#include <gtest/gtest.h>26#include <gtest/gtest.h>
2727
28#include <cstring>
29
28namespace mg = mir::graphics;30namespace mg = mir::graphics;
29namespace mgm = mir::graphics::mesa;31namespace mgm = mir::graphics::mesa;
30namespace mt = mir::test;32namespace mt = mir::test;
@@ -40,38 +42,22 @@
40};42};
41}43}
4244
43namespace mir
44{
45namespace graphics
46{
47
48bool operator==(mg::PlatformOperationMessage const& msg1,
49 mg::PlatformOperationMessage const& msg2)
50{
51 return msg1.data == msg2.data &&
52 msg1.fds == msg1.fds;
53}
54}
55
56}
57
58TEST_F(NestedAuthentication, uses_nested_context_for_auth_magic)45TEST_F(NestedAuthentication, uses_nested_context_for_auth_magic)
59{46{
60 using namespace testing;47 using namespace testing;
6148
62 unsigned int const magic{332211};49 unsigned int const magic{332211};
6350
51 MirMesaAuthMagicRequest const request{magic};
64 mg::PlatformOperationMessage msg;52 mg::PlatformOperationMessage msg;
65 msg.data.resize(sizeof(MirMesaAuthMagicRequest));53 msg.data.resize(sizeof(request));
66 *reinterpret_cast<MirMesaAuthMagicRequest*>(msg.data.data()) =54 std::memcpy(msg.data.data(), &request, sizeof(request));
67 MirMesaAuthMagicRequest{magic};
6855
69 int const success{0};56 MirMesaAuthMagicResponse const success_response{0};
70 mg::PlatformOperationMessage auth_magic_success_response;57 mg::PlatformOperationMessage auth_magic_success_response;
71 auth_magic_success_response.data.resize(sizeof(MirMesaAuthMagicResponse));58 auth_magic_success_response.data.resize(sizeof(success_response));
72 *reinterpret_cast<MirMesaAuthMagicResponse*>(59 std::memcpy(auth_magic_success_response.data.data(), &success_response,
73 auth_magic_success_response.data.data()) =60 sizeof(success_response));
74 MirMesaAuthMagicResponse{success};
7561
76 EXPECT_CALL(mock_nested_context,62 EXPECT_CALL(mock_nested_context,
77 platform_operation(MirMesaPlatformOperation::auth_magic, msg))63 platform_operation(MirMesaPlatformOperation::auth_magic, msg))

Subscribers

People subscribed via source and target branches