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
1=== modified file 'src/platforms/mesa/include/mir_toolkit/mesa/platform_operation.h'
2--- src/platforms/mesa/include/mir_toolkit/mesa/platform_operation.h 2015-01-27 15:14:00 +0000
3+++ src/platforms/mesa/include/mir_toolkit/mesa/platform_operation.h 2015-01-27 15:14:00 +0000
4@@ -34,7 +34,8 @@
5
6 enum MirMesaPlatformOperation
7 {
8- auth_magic = 1
9+ auth_magic = 1,
10+ auth_fd = 2
11 };
12
13 /*
14
15=== modified file 'src/platforms/mesa/server/ipc_operations.cpp'
16--- src/platforms/mesa/server/ipc_operations.cpp 2015-01-27 15:14:00 +0000
17+++ src/platforms/mesa/server/ipc_operations.cpp 2015-01-27 15:14:00 +0000
18@@ -120,6 +120,16 @@
19
20 return response;
21 }
22+ else if (op == MirMesaPlatformOperation::auth_fd)
23+ {
24+ if (request.data.size() != 0 || request.fds.size() != 0)
25+ {
26+ BOOST_THROW_EXCEPTION(
27+ std::runtime_error("Invalid request message for auth_fd platform operation"));
28+ }
29+
30+ return mg::PlatformOperationMessage{{},{drm_auth->authenticated_fd()}};
31+ }
32 else
33 {
34 BOOST_THROW_EXCEPTION(
35
36=== modified file 'src/platforms/mesa/server/nested_authentication.cpp'
37--- src/platforms/mesa/server/nested_authentication.cpp 2015-01-27 15:14:00 +0000
38+++ src/platforms/mesa/server/nested_authentication.cpp 2015-01-27 15:14:00 +0000
39@@ -88,27 +88,23 @@
40
41 mir::Fd mgm::NestedAuthentication::authenticated_fd()
42 {
43- auto fds = nested_context->platform_fd_items();
44- if (fds.size() < 1)
45- BOOST_THROW_EXCEPTION(std::runtime_error("Failed to get fd from platform package"));
46- char* busid = drmGetBusid(fds[0]);
47- if (!busid)
48- BOOST_THROW_EXCEPTION(
49- boost::enable_error_info(
50- std::runtime_error("Failed to get BusID of DRM device")) << boost::errinfo_errno(errno));
51- int auth_fd = drmOpen(NULL, busid);
52- free(busid);
53-
54- drm_magic_t magic;
55- int ret = -1;
56- if ((ret = drmGetMagic(auth_fd, &magic)) < 0)
57- {
58- close(auth_fd);
59- BOOST_THROW_EXCEPTION(
60- boost::enable_error_info(
61- std::runtime_error("Failed to get DRM device magic cookie")) << boost::errinfo_errno(-ret));
62- }
63-
64- auth_magic(magic);
65+ mg::PlatformOperationMessage request_msg;
66+
67+ auto const response_msg = nested_context->platform_operation(
68+ MirMesaPlatformOperation::auth_fd, request_msg);
69+
70+ int auth_fd{-1};
71+
72+ if (response_msg.fds.size() == 1)
73+ {
74+ auth_fd = response_msg.fds[0];
75+ }
76+ else
77+ {
78+ BOOST_THROW_EXCEPTION(
79+ std::runtime_error(
80+ "Nested server failed to get authenticated DRM fd"));
81+ }
82+
83 return mir::Fd(IntOwnedFd{auth_fd});
84 }
85
86=== modified file 'tests/unit-tests/graphics/mesa/test_guest_platform.cpp'
87--- tests/unit-tests/graphics/mesa/test_guest_platform.cpp 2015-01-27 15:14:00 +0000
88+++ tests/unit-tests/graphics/mesa/test_guest_platform.cpp 2015-01-27 15:14:00 +0000
89@@ -61,20 +61,16 @@
90
91 }
92
93-TEST_F(MesaGuestPlatformTest, auth_magic_is_delegated_to_nested_context)
94+TEST_F(MesaGuestPlatformTest, auth_fd_is_delegated_to_nested_context)
95 {
96 using namespace testing;
97
98- int const success{0};
99- mg::PlatformOperationMessage auth_magic_success_response;
100- auth_magic_success_response.data.resize(sizeof(MirMesaAuthMagicResponse));
101- *reinterpret_cast<MirMesaAuthMagicResponse*>(
102- auth_magic_success_response.data.data()) =
103- MirMesaAuthMagicResponse{success};
104+ int const auth_fd{13};
105+ mg::PlatformOperationMessage auth_fd_response{{},{auth_fd}};
106
107 EXPECT_CALL(mock_nested_context,
108- platform_operation(MirMesaPlatformOperation::auth_magic, _))
109- .WillOnce(Return(auth_magic_success_response));
110+ platform_operation(MirMesaPlatformOperation::auth_fd, _))
111+ .WillOnce(Return(auth_fd_response));
112
113 mgm::GuestPlatform native(mt::fake_shared(mock_nested_context));
114 auto ipc_ops = native.make_ipc_operations();
115
116=== modified file 'tests/unit-tests/graphics/mesa/test_ipc_operations.cpp'
117--- tests/unit-tests/graphics/mesa/test_ipc_operations.cpp 2015-01-27 15:14:00 +0000
118+++ tests/unit-tests/graphics/mesa/test_ipc_operations.cpp 2015-01-27 15:14:00 +0000
119@@ -112,6 +112,23 @@
120 EXPECT_THAT(response.status, Eq(0));
121 }
122
123+TEST_F(IpcOperations, gets_authentication_fd_for_auth_fd_operation)
124+{
125+ using namespace testing;
126+
127+ mir::Fd stub_fd(fileno(tmpfile()));
128+ EXPECT_CALL(mock_drm_ops, authenticated_fd())
129+ .WillOnce(Return(stub_fd));
130+
131+ mg::PlatformOperationMessage request_msg;
132+
133+ auto const response_msg = ipc_ops.platform_operation(
134+ MirMesaPlatformOperation::auth_fd, request_msg);
135+
136+ EXPECT_THAT(response_msg.data, IsEmpty());
137+ EXPECT_THAT(response_msg.fds, ElementsAre(stub_fd));
138+}
139+
140 TEST_F(IpcOperations, gets_authentication_fd_for_connection_package)
141 {
142 using namespace testing;
143
144=== modified file 'tests/unit-tests/graphics/mesa/test_nested_authentication.cpp'
145--- tests/unit-tests/graphics/mesa/test_nested_authentication.cpp 2015-01-27 15:14:00 +0000
146+++ tests/unit-tests/graphics/mesa/test_nested_authentication.cpp 2015-01-27 15:14:00 +0000
147@@ -34,19 +34,9 @@
148 {
149 struct NestedAuthentication : public ::testing::Test
150 {
151- NestedAuthentication()
152- {
153- int const success{0};
154- auth_magic_success_response.data.resize(sizeof(MirMesaAuthMagicResponse));
155- *reinterpret_cast<MirMesaAuthMagicResponse*>(
156- auth_magic_success_response.data.data()) =
157- MirMesaAuthMagicResponse{success};
158- }
159-
160 ::testing::NiceMock<mtd::MockDRM> mock_drm;
161 mtd::MockNestedContext mock_nested_context;
162 mgm::NestedAuthentication auth{mt::fake_shared(mock_nested_context)};
163- mg::PlatformOperationMessage auth_magic_success_response;
164 };
165 }
166
167@@ -65,7 +55,7 @@
168
169 }
170
171-TEST_F(NestedAuthentication, uses_nested_context_to_authenticate)
172+TEST_F(NestedAuthentication, uses_nested_context_for_auth_magic)
173 {
174 using namespace testing;
175
176@@ -76,6 +66,13 @@
177 *reinterpret_cast<MirMesaAuthMagicRequest*>(msg.data.data()) =
178 MirMesaAuthMagicRequest{magic};
179
180+ int const success{0};
181+ mg::PlatformOperationMessage auth_magic_success_response;
182+ auth_magic_success_response.data.resize(sizeof(MirMesaAuthMagicResponse));
183+ *reinterpret_cast<MirMesaAuthMagicResponse*>(
184+ auth_magic_success_response.data.data()) =
185+ MirMesaAuthMagicResponse{success};
186+
187 EXPECT_CALL(mock_nested_context,
188 platform_operation(MirMesaPlatformOperation::auth_magic, msg))
189 .WillOnce(Return(auth_magic_success_response));
190@@ -83,80 +80,18 @@
191 auth.auth_magic(magic);
192 }
193
194-TEST_F(NestedAuthentication, no_drm_in_platform_package_throws)
195-{
196- using namespace testing;
197- EXPECT_CALL(mock_nested_context, platform_fd_items())
198- .WillOnce(Return(std::vector<int>{}));
199- EXPECT_THROW({
200- auth.authenticated_fd();
201- }, std::runtime_error);
202-}
203-
204-TEST_F(NestedAuthentication, failure_in_getbusid_throws)
205-{
206- using namespace testing;
207- int stub_fd = 33;
208-
209- InSequence seq;
210- EXPECT_CALL(mock_nested_context, platform_fd_items())
211- .WillOnce(Return(std::vector<int>{stub_fd}));
212- EXPECT_CALL(mock_drm, drmGetBusid(stub_fd))
213- .WillOnce(Return(nullptr));
214-
215- EXPECT_THROW({
216- auth.authenticated_fd();
217- }, std::runtime_error);
218-}
219-
220-TEST_F(NestedAuthentication, failure_in_getmagic_throws)
221-{
222- using namespace testing;
223- int stub_fd = 33;
224- int auth_fd = 34;
225- //this should get freed by the implementation
226- auto fake_busid = static_cast<char*>(malloc(sizeof(char)));
227- *fake_busid = 'a';
228- int magic{332211};
229-
230- InSequence seq;
231- EXPECT_CALL(mock_nested_context, platform_fd_items())
232- .WillOnce(Return(std::vector<int>{stub_fd}));
233- EXPECT_CALL(mock_drm, drmGetBusid(stub_fd))
234- .WillOnce(Return(fake_busid));
235- EXPECT_CALL(mock_drm, drmOpen(nullptr, fake_busid))
236- .WillOnce(Return(auth_fd));
237- EXPECT_CALL(mock_drm, drmGetMagic(auth_fd, _))
238- .WillOnce(DoAll(SetArgPointee<1>(magic), Return(-1)));
239-
240- EXPECT_THROW({
241- auth.authenticated_fd();
242- }, std::runtime_error);
243-}
244-
245-TEST_F(NestedAuthentication, creates_new_fd)
246-{
247- using namespace testing;
248- int stub_fd = 33;
249- int auth_fd = 34;
250- //this should get freed by the implementation
251- auto fake_busid = static_cast<char*>(malloc(sizeof(char)));
252- *fake_busid = 'a';
253- int magic{332211};
254-
255- InSequence seq;
256- EXPECT_CALL(mock_nested_context, platform_fd_items())
257- .WillOnce(Return(std::vector<int>{stub_fd}));
258- EXPECT_CALL(mock_drm, drmGetBusid(stub_fd))
259- .WillOnce(Return(fake_busid));
260- EXPECT_CALL(mock_drm, drmOpen(nullptr, fake_busid))
261- .WillOnce(Return(auth_fd));
262- EXPECT_CALL(mock_drm, drmGetMagic(auth_fd, _))
263- .WillOnce(DoAll(SetArgPointee<1>(magic), Return(0)));
264+TEST_F(NestedAuthentication, uses_nested_context_for_auth_fd)
265+{
266+ using namespace testing;
267+
268+ mg::PlatformOperationMessage msg;
269+
270+ int const auth_fd{13};
271+ mg::PlatformOperationMessage const response{{}, {auth_fd}};
272+
273 EXPECT_CALL(mock_nested_context,
274- platform_operation(MirMesaPlatformOperation::auth_magic, _))
275- .WillOnce(Return(auth_magic_success_response));
276+ platform_operation(MirMesaPlatformOperation::auth_fd, msg))
277+ .WillOnce(Return(response));
278
279- auto fd = auth.authenticated_fd();
280- EXPECT_THAT(fd, Eq(auth_fd));
281+ EXPECT_THAT(auth.authenticated_fd(), Eq(auth_fd));
282 }

Subscribers

People subscribed via source and target branches