Mir

Merge lp:~afrantzis/mir/platform-operation-auth-fd into lp:mir

Proposed by Alexandros Frantzis
Status: Merged
Approved by: Cemil Azizoglu
Approved revision: no longer in the source branch.
Merged at revision: 2278
Proposed branch: lp:~afrantzis/mir/platform-operation-auth-fd
Merge into: lp:mir
Prerequisite: lp:~afrantzis/mir/platform-operation-auth-magic
Diff against target: 282 lines (+72/-117)
6 files modified
src/platforms/mesa/include/mir_toolkit/mesa/platform_operation.h (+2/-1)
src/platforms/mesa/server/ipc_operations.cpp (+10/-0)
src/platforms/mesa/server/nested_authentication.cpp (+18/-22)
tests/unit-tests/graphics/mesa/test_guest_platform.cpp (+5/-9)
tests/unit-tests/graphics/mesa/test_ipc_operations.cpp (+17/-0)
tests/unit-tests/graphics/mesa/test_nested_authentication.cpp (+20/-85)
To merge this branch: bzr merge lp:~afrantzis/mir/platform-operation-auth-fd
Reviewer Review Type Date Requested Status
Cemil Azizoglu (community) Approve
Alan Griffiths Approve
PS Jenkins bot (community) continuous-integration Approve
Review via email: mp+247722@code.launchpad.net

This proposal supersedes a proposal from 2015-01-27.

Commit message

mesa: Add auth_fd platform operation

Description of the change

mesa: Add auth_fd platform operation

This MP adds a new Mesa platform operation needed for resolving bug 1379266.

It's also a nice example of how the new platform operation infrastructure allows adding new operations without affecting the mir core code at all.

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
Alan Griffiths (alan-griffiths) wrote :

LGTM

review: Approve
Revision history for this message
Cemil Azizoglu (cemil-azizoglu) wrote :

Looks good.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'src/platforms/mesa/include/mir_toolkit/mesa/platform_operation.h'
--- src/platforms/mesa/include/mir_toolkit/mesa/platform_operation.h 2015-01-27 15:14:00 +0000
+++ src/platforms/mesa/include/mir_toolkit/mesa/platform_operation.h 2015-01-27 15:14:00 +0000
@@ -34,7 +34,8 @@
3434
35enum MirMesaPlatformOperation35enum MirMesaPlatformOperation
36{36{
37 auth_magic = 137 auth_magic = 1,
38 auth_fd = 2
38};39};
3940
40/*41/*
4142
=== modified file 'src/platforms/mesa/server/ipc_operations.cpp'
--- src/platforms/mesa/server/ipc_operations.cpp 2015-01-27 15:14:00 +0000
+++ src/platforms/mesa/server/ipc_operations.cpp 2015-01-27 15:14:00 +0000
@@ -120,6 +120,16 @@
120120
121 return response;121 return response;
122 }122 }
123 else if (op == MirMesaPlatformOperation::auth_fd)
124 {
125 if (request.data.size() != 0 || request.fds.size() != 0)
126 {
127 BOOST_THROW_EXCEPTION(
128 std::runtime_error("Invalid request message for auth_fd platform operation"));
129 }
130
131 return mg::PlatformOperationMessage{{},{drm_auth->authenticated_fd()}};
132 }
123 else133 else
124 {134 {
125 BOOST_THROW_EXCEPTION(135 BOOST_THROW_EXCEPTION(
126136
=== modified file 'src/platforms/mesa/server/nested_authentication.cpp'
--- src/platforms/mesa/server/nested_authentication.cpp 2015-01-27 15:14:00 +0000
+++ src/platforms/mesa/server/nested_authentication.cpp 2015-01-27 15:14:00 +0000
@@ -88,27 +88,23 @@
8888
89mir::Fd mgm::NestedAuthentication::authenticated_fd()89mir::Fd mgm::NestedAuthentication::authenticated_fd()
90{90{
91 auto fds = nested_context->platform_fd_items();91 mg::PlatformOperationMessage request_msg;
92 if (fds.size() < 1)92
93 BOOST_THROW_EXCEPTION(std::runtime_error("Failed to get fd from platform package"));93 auto const response_msg = nested_context->platform_operation(
94 char* busid = drmGetBusid(fds[0]);94 MirMesaPlatformOperation::auth_fd, request_msg);
95 if (!busid)95
96 BOOST_THROW_EXCEPTION(96 int auth_fd{-1};
97 boost::enable_error_info(97
98 std::runtime_error("Failed to get BusID of DRM device")) << boost::errinfo_errno(errno));98 if (response_msg.fds.size() == 1)
99 int auth_fd = drmOpen(NULL, busid);99 {
100 free(busid);100 auth_fd = response_msg.fds[0];
101101 }
102 drm_magic_t magic;102 else
103 int ret = -1;103 {
104 if ((ret = drmGetMagic(auth_fd, &magic)) < 0)104 BOOST_THROW_EXCEPTION(
105 {105 std::runtime_error(
106 close(auth_fd);106 "Nested server failed to get authenticated DRM fd"));
107 BOOST_THROW_EXCEPTION(107 }
108 boost::enable_error_info(108
109 std::runtime_error("Failed to get DRM device magic cookie")) << boost::errinfo_errno(-ret));
110 }
111
112 auth_magic(magic);
113 return mir::Fd(IntOwnedFd{auth_fd});109 return mir::Fd(IntOwnedFd{auth_fd});
114}110}
115111
=== modified file 'tests/unit-tests/graphics/mesa/test_guest_platform.cpp'
--- tests/unit-tests/graphics/mesa/test_guest_platform.cpp 2015-01-27 15:14:00 +0000
+++ tests/unit-tests/graphics/mesa/test_guest_platform.cpp 2015-01-27 15:14:00 +0000
@@ -61,20 +61,16 @@
6161
62}62}
6363
64TEST_F(MesaGuestPlatformTest, auth_magic_is_delegated_to_nested_context)64TEST_F(MesaGuestPlatformTest, auth_fd_is_delegated_to_nested_context)
65{65{
66 using namespace testing;66 using namespace testing;
6767
68 int const success{0};68 int const auth_fd{13};
69 mg::PlatformOperationMessage auth_magic_success_response;69 mg::PlatformOperationMessage auth_fd_response{{},{auth_fd}};
70 auth_magic_success_response.data.resize(sizeof(MirMesaAuthMagicResponse));
71 *reinterpret_cast<MirMesaAuthMagicResponse*>(
72 auth_magic_success_response.data.data()) =
73 MirMesaAuthMagicResponse{success};
7470
75 EXPECT_CALL(mock_nested_context,71 EXPECT_CALL(mock_nested_context,
76 platform_operation(MirMesaPlatformOperation::auth_magic, _))72 platform_operation(MirMesaPlatformOperation::auth_fd, _))
77 .WillOnce(Return(auth_magic_success_response));73 .WillOnce(Return(auth_fd_response));
7874
79 mgm::GuestPlatform native(mt::fake_shared(mock_nested_context));75 mgm::GuestPlatform native(mt::fake_shared(mock_nested_context));
80 auto ipc_ops = native.make_ipc_operations();76 auto ipc_ops = native.make_ipc_operations();
8177
=== modified file 'tests/unit-tests/graphics/mesa/test_ipc_operations.cpp'
--- tests/unit-tests/graphics/mesa/test_ipc_operations.cpp 2015-01-27 15:14:00 +0000
+++ tests/unit-tests/graphics/mesa/test_ipc_operations.cpp 2015-01-27 15:14:00 +0000
@@ -112,6 +112,23 @@
112 EXPECT_THAT(response.status, Eq(0));112 EXPECT_THAT(response.status, Eq(0));
113}113}
114114
115TEST_F(IpcOperations, gets_authentication_fd_for_auth_fd_operation)
116{
117 using namespace testing;
118
119 mir::Fd stub_fd(fileno(tmpfile()));
120 EXPECT_CALL(mock_drm_ops, authenticated_fd())
121 .WillOnce(Return(stub_fd));
122
123 mg::PlatformOperationMessage request_msg;
124
125 auto const response_msg = ipc_ops.platform_operation(
126 MirMesaPlatformOperation::auth_fd, request_msg);
127
128 EXPECT_THAT(response_msg.data, IsEmpty());
129 EXPECT_THAT(response_msg.fds, ElementsAre(stub_fd));
130}
131
115TEST_F(IpcOperations, gets_authentication_fd_for_connection_package)132TEST_F(IpcOperations, gets_authentication_fd_for_connection_package)
116{133{
117 using namespace testing;134 using namespace testing;
118135
=== modified file 'tests/unit-tests/graphics/mesa/test_nested_authentication.cpp'
--- tests/unit-tests/graphics/mesa/test_nested_authentication.cpp 2015-01-27 15:14:00 +0000
+++ tests/unit-tests/graphics/mesa/test_nested_authentication.cpp 2015-01-27 15:14:00 +0000
@@ -34,19 +34,9 @@
34{34{
35struct NestedAuthentication : public ::testing::Test35struct NestedAuthentication : public ::testing::Test
36{36{
37 NestedAuthentication()
38 {
39 int const success{0};
40 auth_magic_success_response.data.resize(sizeof(MirMesaAuthMagicResponse));
41 *reinterpret_cast<MirMesaAuthMagicResponse*>(
42 auth_magic_success_response.data.data()) =
43 MirMesaAuthMagicResponse{success};
44 }
45
46 ::testing::NiceMock<mtd::MockDRM> mock_drm;37 ::testing::NiceMock<mtd::MockDRM> mock_drm;
47 mtd::MockNestedContext mock_nested_context;38 mtd::MockNestedContext mock_nested_context;
48 mgm::NestedAuthentication auth{mt::fake_shared(mock_nested_context)};39 mgm::NestedAuthentication auth{mt::fake_shared(mock_nested_context)};
49 mg::PlatformOperationMessage auth_magic_success_response;
50};40};
51}41}
5242
@@ -65,7 +55,7 @@
6555
66}56}
6757
68TEST_F(NestedAuthentication, uses_nested_context_to_authenticate)58TEST_F(NestedAuthentication, uses_nested_context_for_auth_magic)
69{59{
70 using namespace testing;60 using namespace testing;
7161
@@ -76,6 +66,13 @@
76 *reinterpret_cast<MirMesaAuthMagicRequest*>(msg.data.data()) =66 *reinterpret_cast<MirMesaAuthMagicRequest*>(msg.data.data()) =
77 MirMesaAuthMagicRequest{magic};67 MirMesaAuthMagicRequest{magic};
7868
69 int const success{0};
70 mg::PlatformOperationMessage auth_magic_success_response;
71 auth_magic_success_response.data.resize(sizeof(MirMesaAuthMagicResponse));
72 *reinterpret_cast<MirMesaAuthMagicResponse*>(
73 auth_magic_success_response.data.data()) =
74 MirMesaAuthMagicResponse{success};
75
79 EXPECT_CALL(mock_nested_context,76 EXPECT_CALL(mock_nested_context,
80 platform_operation(MirMesaPlatformOperation::auth_magic, msg))77 platform_operation(MirMesaPlatformOperation::auth_magic, msg))
81 .WillOnce(Return(auth_magic_success_response));78 .WillOnce(Return(auth_magic_success_response));
@@ -83,80 +80,18 @@
83 auth.auth_magic(magic);80 auth.auth_magic(magic);
84}81}
8582
86TEST_F(NestedAuthentication, no_drm_in_platform_package_throws)83TEST_F(NestedAuthentication, uses_nested_context_for_auth_fd)
87{84{
88 using namespace testing;85 using namespace testing;
89 EXPECT_CALL(mock_nested_context, platform_fd_items())86
90 .WillOnce(Return(std::vector<int>{}));87 mg::PlatformOperationMessage msg;
91 EXPECT_THROW({88
92 auth.authenticated_fd();89 int const auth_fd{13};
93 }, std::runtime_error);90 mg::PlatformOperationMessage const response{{}, {auth_fd}};
94}91
95
96TEST_F(NestedAuthentication, failure_in_getbusid_throws)
97{
98 using namespace testing;
99 int stub_fd = 33;
100
101 InSequence seq;
102 EXPECT_CALL(mock_nested_context, platform_fd_items())
103 .WillOnce(Return(std::vector<int>{stub_fd}));
104 EXPECT_CALL(mock_drm, drmGetBusid(stub_fd))
105 .WillOnce(Return(nullptr));
106
107 EXPECT_THROW({
108 auth.authenticated_fd();
109 }, std::runtime_error);
110}
111
112TEST_F(NestedAuthentication, failure_in_getmagic_throws)
113{
114 using namespace testing;
115 int stub_fd = 33;
116 int auth_fd = 34;
117 //this should get freed by the implementation
118 auto fake_busid = static_cast<char*>(malloc(sizeof(char)));
119 *fake_busid = 'a';
120 int magic{332211};
121
122 InSequence seq;
123 EXPECT_CALL(mock_nested_context, platform_fd_items())
124 .WillOnce(Return(std::vector<int>{stub_fd}));
125 EXPECT_CALL(mock_drm, drmGetBusid(stub_fd))
126 .WillOnce(Return(fake_busid));
127 EXPECT_CALL(mock_drm, drmOpen(nullptr, fake_busid))
128 .WillOnce(Return(auth_fd));
129 EXPECT_CALL(mock_drm, drmGetMagic(auth_fd, _))
130 .WillOnce(DoAll(SetArgPointee<1>(magic), Return(-1)));
131
132 EXPECT_THROW({
133 auth.authenticated_fd();
134 }, std::runtime_error);
135}
136
137TEST_F(NestedAuthentication, creates_new_fd)
138{
139 using namespace testing;
140 int stub_fd = 33;
141 int auth_fd = 34;
142 //this should get freed by the implementation
143 auto fake_busid = static_cast<char*>(malloc(sizeof(char)));
144 *fake_busid = 'a';
145 int magic{332211};
146
147 InSequence seq;
148 EXPECT_CALL(mock_nested_context, platform_fd_items())
149 .WillOnce(Return(std::vector<int>{stub_fd}));
150 EXPECT_CALL(mock_drm, drmGetBusid(stub_fd))
151 .WillOnce(Return(fake_busid));
152 EXPECT_CALL(mock_drm, drmOpen(nullptr, fake_busid))
153 .WillOnce(Return(auth_fd));
154 EXPECT_CALL(mock_drm, drmGetMagic(auth_fd, _))
155 .WillOnce(DoAll(SetArgPointee<1>(magic), Return(0)));
156 EXPECT_CALL(mock_nested_context,92 EXPECT_CALL(mock_nested_context,
157 platform_operation(MirMesaPlatformOperation::auth_magic, _))93 platform_operation(MirMesaPlatformOperation::auth_fd, msg))
158 .WillOnce(Return(auth_magic_success_response));94 .WillOnce(Return(response));
15995
160 auto fd = auth.authenticated_fd();96 EXPECT_THAT(auth.authenticated_fd(), Eq(auth_fd));
161 EXPECT_THAT(fd, Eq(auth_fd));
162}97}

Subscribers

People subscribed via source and target branches