Mir

Merge lp:~kdub/mir/fix-1192742 into lp:~mir-team/mir/trunk

Proposed by Kevin DuBois
Status: Merged
Approved by: Kevin DuBois
Approved revision: no longer in the source branch.
Merged at revision: 803
Proposed branch: lp:~kdub/mir/fix-1192742
Merge into: lp:~mir-team/mir/trunk
Diff against target: 71 lines (+25/-1)
2 files modified
src/client/android/android_registrar.cpp (+2/-0)
tests/unit-tests/client/android/test_client_android_registrar.cpp (+23/-1)
To merge this branch: bzr merge lp:~kdub/mir/fix-1192742
Reviewer Review Type Date Requested Status
PS Jenkins bot (community) continuous-integration Approve
Alan Griffiths Abstain
Alexandros Frantzis (community) Approve
Review via email: mp+172667@code.launchpad.net

Commit message

fix: lp1192742 by cleaning up FD's when an android client unregisters its native_handle_t

Description of the change

fix: lp1192742 by cleaning up FD's when an android client unregisters its native_handle_t

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.

48 + mcla::AndroidRegistrarGralloc registrar(mock_module);

This calls for a Stub/NullModule, since no expectations are checked, but I won't block.

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

> Looks good.
>
> 48 + mcla::AndroidRegistrarGralloc registrar(mock_module);
>
> This calls for a Stub/NullModule, since no expectations are checked, but I
> won't block.

+1

review: Abstain
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
1=== modified file 'src/client/android/android_registrar.cpp'
2--- src/client/android/android_registrar.cpp 2013-06-21 23:35:50 +0000
3+++ src/client/android/android_registrar.cpp 2013-07-03 17:18:27 +0000
4@@ -37,6 +37,8 @@
5 void operator()(const native_handle_t* t)
6 {
7 module->unregisterBuffer(module.get(), t);
8+ for(auto i=0; i < t->numFds; i++)
9+ close(t->data[i]);
10 ::operator delete(const_cast<native_handle_t*>(t));
11 }
12 private:
13
14=== modified file 'tests/unit-tests/client/android/test_client_android_registrar.cpp'
15--- tests/unit-tests/client/android/test_client_android_registrar.cpp 2013-06-21 23:04:37 +0000
16+++ tests/unit-tests/client/android/test_client_android_registrar.cpp 2013-07-03 17:18:27 +0000
17@@ -19,9 +19,12 @@
18 #include "src/client/android/android_client_buffer.h"
19 #include "src/client/android/android_registrar_gralloc.h"
20 #include "mir_test_doubles/mock_android_alloc_device.h"
21+#include "mir_test/fake_shared.h"
22
23 #include <system/graphics.h>
24 #include <stdexcept>
25+#include <unistd.h>
26+#include <fcntl.h>
27
28 #include <gtest/gtest.h>
29 #include <gmock/gmock.h>
30@@ -82,6 +85,7 @@
31 return registrar->unlock_interface(module, handle);
32 }
33 };
34+typedef ::testing::NiceMock<MockRegistrarDevice> StubRegistrarDevice;
35
36 class ClientAndroidRegistrarTest : public ::testing::Test
37 {
38@@ -90,7 +94,7 @@
39 {
40 using namespace testing;
41
42- mock_module = std::make_shared<MockRegistrarDevice>();
43+ mock_module = std::make_shared<NiceMock<MockRegistrarDevice>>();
44
45 width = 41;
46 height = 43;
47@@ -158,6 +162,24 @@
48 EXPECT_EQ(handle1, handle2);
49 }
50
51+TEST_F(ClientAndroidRegistrarTest, registrar_frees_fds)
52+{
53+ using namespace testing;
54+ StubRegistrarDevice stub_module;
55+ auto package = std::make_shared<MirBufferPackage>();
56+ package->data_items = 0;
57+ package->fd_items = 2;
58+ pipe(static_cast<int*>(package->fd));
59+
60+ {
61+ mcla::AndroidRegistrarGralloc registrar(mir::test::fake_shared(stub_module));
62+ auto handle = registrar.register_buffer(package);
63+ }
64+
65+ EXPECT_EQ(-1, fcntl(package->fd[0], F_GETFD));
66+ EXPECT_EQ(-1, fcntl(package->fd[1], F_GETFD));
67+}
68+
69
70 TEST_F(ClientAndroidRegistrarTest, register_failure)
71 {

Subscribers

People subscribed via source and target branches