2
* Copyright © 2012 Canonical Ltd.
4
* This program is free software: you can redistribute it and/or modify
5
* it under the terms of the GNU General Public License version 3 as
6
* published by the Free Software Foundation.
8
* This program is distributed in the hope that it will be useful,
9
* but WITHOUT ANY WARRANTY; without even the implied warranty of
10
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
* GNU General Public License for more details.
13
* You should have received a copy of the GNU General Public License
14
* along with this program. If not, see <http://www.gnu.org/licenses/>.
16
* Authored by: Kevin DuBois <kevin.dubois@canonical.com>
19
#include "src/server/report/null_report_factory.h"
20
#include "mir/graphics/native_platform.h"
21
#include "mir/graphics/buffer_ipc_packer.h"
22
#include "mir/options/program_option.h"
23
#include "src/platform/graphics/android/android_platform.h"
24
#include "mir_test_doubles/mock_buffer.h"
25
#include "mir_test_doubles/mock_android_hw.h"
26
#include "mir_test_doubles/mock_buffer_packer.h"
27
#include "mir_test_doubles/mock_display_report.h"
28
#include "mir_test_doubles/stub_display_builder.h"
29
#include "mir_test_doubles/fd_matcher.h"
30
#include "mir_test/fake_shared.h"
31
#include "mir_test_doubles/mock_android_native_buffer.h"
32
#include <system/window.h>
33
#include <gtest/gtest.h>
35
namespace mg=mir::graphics;
36
namespace mga=mir::graphics::android;
37
namespace mt=mir::test;
38
namespace mtd=mir::test::doubles;
39
namespace mr=mir::report;
40
namespace geom=mir::geometry;
41
namespace mo=mir::options;
43
class PlatformBufferIPCPackaging : public ::testing::Test
48
using namespace testing;
50
stub_display_builder = std::make_shared<mtd::StubDisplayBuilder>();
51
stub_display_report = mr::null_display_report();
52
stride = geom::Stride(300*4);
56
auto handle_size = sizeof(native_handle_t) + (sizeof(int)*(num_ints + num_fds));
57
auto native_buffer_raw = (native_handle_t*) ::operator new(handle_size);
58
native_buffer_handle = std::shared_ptr<native_handle_t>(native_buffer_raw);
60
native_buffer_handle->numInts = num_ints;
61
native_buffer_handle->numFds = num_fds;
62
for(auto i=0u; i< (num_ints+num_fds); i++)
64
native_buffer_handle->data[i] = i;
67
native_buffer = std::make_shared<mtd::StubAndroidNativeBuffer>();
68
mock_buffer = std::make_shared<NiceMock<mtd::MockBuffer>>();
70
ON_CALL(*native_buffer, handle())
71
.WillByDefault(Return(native_buffer_handle.get()));
72
ON_CALL(*mock_buffer, native_buffer_handle())
73
.WillByDefault(Return(native_buffer));
74
ON_CALL(*mock_buffer, stride())
75
.WillByDefault(Return(stride));
78
std::shared_ptr<mtd::MockAndroidNativeBuffer> native_buffer;
79
std::shared_ptr<mtd::StubDisplayBuilder> stub_display_builder;
80
std::shared_ptr<mtd::MockBuffer> mock_buffer;
81
std::shared_ptr<native_handle_t> native_buffer_handle;
82
std::shared_ptr<mg::DisplayReport> stub_display_report;
84
unsigned int num_ints, num_fds;
87
/* ipc packaging tests */
88
TEST_F(PlatformBufferIPCPackaging, test_ipc_data_packed_correctly_for_full_ipc)
90
using namespace ::testing;
92
mga::AndroidPlatform platform(stub_display_builder, stub_display_report);
94
mtd::MockPacker mock_packer;
96
for(auto i=0u; i<num_fds; i++)
98
EXPECT_CALL(mock_packer, pack_fd(mtd::RawFdMatcher(native_buffer_handle->data[offset++])))
101
for(auto i=0u; i<num_ints; i++)
103
EXPECT_CALL(mock_packer, pack_data(native_buffer_handle->data[offset++]))
107
EXPECT_CALL(*mock_buffer, stride())
108
.WillOnce(Return(stride));
109
EXPECT_CALL(mock_packer, pack_stride(stride))
112
EXPECT_CALL(*mock_buffer, size())
113
.WillOnce(Return(mir::geometry::Size{123, 456}));
114
EXPECT_CALL(mock_packer, pack_size(_))
117
EXPECT_CALL(*native_buffer, ensure_available_for(mga::BufferAccess::write))
120
platform.fill_buffer_package(
121
&mock_packer, mock_buffer.get(), mg::BufferIpcMsgType::full_msg);
124
TEST_F(PlatformBufferIPCPackaging, test_ipc_data_packed_correctly_for_partial_ipc)
126
using namespace ::testing;
128
mga::AndroidPlatform platform(stub_display_builder, stub_display_report);
130
mtd::MockPacker mock_packer;
131
EXPECT_CALL(mock_packer, pack_fd(_))
133
EXPECT_CALL(mock_packer, pack_data(_))
135
EXPECT_CALL(mock_packer, pack_stride(_))
137
EXPECT_CALL(mock_packer, pack_size(_))
140
/* TODO: instead of waiting, pass the fd along */
141
EXPECT_CALL(*native_buffer, ensure_available_for(mga::BufferAccess::write))
144
platform.fill_buffer_package(
145
&mock_packer, mock_buffer.get(), mg::BufferIpcMsgType::update_msg);
148
TEST(AndroidGraphicsPlatform, egl_native_display_is_egl_default_display)
150
mga::AndroidPlatform platform(
151
std::make_shared<mtd::StubDisplayBuilder>(),
152
mr::null_display_report());
154
EXPECT_EQ(EGL_DEFAULT_DISPLAY, platform.egl_native_display());
157
TEST(NestedPlatformCreation, doesnt_access_display_hardware)
159
using namespace testing;
161
mtd::HardwareAccessMock hwaccess;
162
mtd::MockDisplayReport stub_report;
164
EXPECT_CALL(hwaccess, hw_get_module(StrEq(HWC_HARDWARE_MODULE_ID), _))
166
EXPECT_CALL(hwaccess, hw_get_module(StrEq(GRALLOC_HARDWARE_MODULE_ID), _))
169
auto platform = mg::create_native_platform(mt::fake_shared(stub_report));