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
=== modified file 'src/client/android/android_registrar.cpp'
--- src/client/android/android_registrar.cpp 2013-06-21 23:35:50 +0000
+++ src/client/android/android_registrar.cpp 2013-07-03 17:18:27 +0000
@@ -37,6 +37,8 @@
37 void operator()(const native_handle_t* t)37 void operator()(const native_handle_t* t)
38 {38 {
39 module->unregisterBuffer(module.get(), t);39 module->unregisterBuffer(module.get(), t);
40 for(auto i=0; i < t->numFds; i++)
41 close(t->data[i]);
40 ::operator delete(const_cast<native_handle_t*>(t));42 ::operator delete(const_cast<native_handle_t*>(t));
41 }43 }
42private:44private:
4345
=== modified file 'tests/unit-tests/client/android/test_client_android_registrar.cpp'
--- tests/unit-tests/client/android/test_client_android_registrar.cpp 2013-06-21 23:04:37 +0000
+++ tests/unit-tests/client/android/test_client_android_registrar.cpp 2013-07-03 17:18:27 +0000
@@ -19,9 +19,12 @@
19#include "src/client/android/android_client_buffer.h"19#include "src/client/android/android_client_buffer.h"
20#include "src/client/android/android_registrar_gralloc.h"20#include "src/client/android/android_registrar_gralloc.h"
21#include "mir_test_doubles/mock_android_alloc_device.h"21#include "mir_test_doubles/mock_android_alloc_device.h"
22#include "mir_test/fake_shared.h"
2223
23#include <system/graphics.h>24#include <system/graphics.h>
24#include <stdexcept>25#include <stdexcept>
26#include <unistd.h>
27#include <fcntl.h>
2528
26#include <gtest/gtest.h>29#include <gtest/gtest.h>
27#include <gmock/gmock.h>30#include <gmock/gmock.h>
@@ -82,6 +85,7 @@
82 return registrar->unlock_interface(module, handle);85 return registrar->unlock_interface(module, handle);
83 }86 }
84};87};
88typedef ::testing::NiceMock<MockRegistrarDevice> StubRegistrarDevice;
8589
86class ClientAndroidRegistrarTest : public ::testing::Test90class ClientAndroidRegistrarTest : public ::testing::Test
87{91{
@@ -90,7 +94,7 @@
90 {94 {
91 using namespace testing;95 using namespace testing;
9296
93 mock_module = std::make_shared<MockRegistrarDevice>();97 mock_module = std::make_shared<NiceMock<MockRegistrarDevice>>();
9498
95 width = 41;99 width = 41;
96 height = 43;100 height = 43;
@@ -158,6 +162,24 @@
158 EXPECT_EQ(handle1, handle2);162 EXPECT_EQ(handle1, handle2);
159}163}
160164
165TEST_F(ClientAndroidRegistrarTest, registrar_frees_fds)
166{
167 using namespace testing;
168 StubRegistrarDevice stub_module;
169 auto package = std::make_shared<MirBufferPackage>();
170 package->data_items = 0;
171 package->fd_items = 2;
172 pipe(static_cast<int*>(package->fd));
173
174 {
175 mcla::AndroidRegistrarGralloc registrar(mir::test::fake_shared(stub_module));
176 auto handle = registrar.register_buffer(package);
177 }
178
179 EXPECT_EQ(-1, fcntl(package->fd[0], F_GETFD));
180 EXPECT_EQ(-1, fcntl(package->fd[1], F_GETFD));
181}
182
161183
162TEST_F(ClientAndroidRegistrarTest, register_failure)184TEST_F(ClientAndroidRegistrarTest, register_failure)
163{185{

Subscribers

People subscribed via source and target branches