~raof/mir/prober-drm-device-probe

« back to all changes in this revision

Viewing changes to tests/unit-tests/graphics/android/test_hwc11_device.cpp

  • Committer: Daniel van Vugt
  • Date: 2013-04-24 05:18:38 UTC
  • mfrom: (627 trunk)
  • mto: This revision was merged to the branch mainline in revision 629.
  • Revision ID: daniel.van.vugt@canonical.com-20130424051838-bxzdvlavdj3y051r
Merge latest lp:mir

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright © 2013 Canonical Ltd.
 
3
 *
 
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.
 
7
 *
 
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.
 
12
 *
 
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/>.
 
15
 *
 
16
 * Authored by: Kevin DuBois <kevin.dubois@canonical.com>
 
17
 */
 
18
 
 
19
#include "src/server/graphics/android/hwc11_device.h"
 
20
#include "src/server/graphics/android/hwc_layerlist.h"
 
21
#include "mir_test_doubles/mock_display_support_provider.h"
 
22
#include "mir_test_doubles/mock_hwc_composer_device_1.h"
 
23
#include "mir_test_doubles/mock_hwc_organizer.h"
 
24
#include "mir_test_doubles/mock_android_buffer.h"
 
25
#include "mir_test/egl_mock.h"
 
26
#include <gtest/gtest.h>
 
27
 
 
28
namespace mga=mir::graphics::android;
 
29
namespace mtd=mir::test::doubles;
 
30
 
 
31
class HWC11Device : public ::testing::Test
 
32
{
 
33
protected:
 
34
    virtual void SetUp()
 
35
    {
 
36
        mock_device = std::make_shared<testing::NiceMock<mtd::MockHWCComposerDevice1>>();
 
37
        mock_display_support_provider = std::make_shared<testing::NiceMock<mtd::MockDisplaySupportProvider>>();
 
38
        mock_organizer = std::make_shared<testing::NiceMock<mtd::MockHWCOrganizer>>();
 
39
        mock_egl.silence_uninteresting();
 
40
    }
 
41
 
 
42
    std::shared_ptr<mtd::MockHWCOrganizer> mock_organizer;
 
43
    std::shared_ptr<mtd::MockHWCComposerDevice1> mock_device;
 
44
    std::shared_ptr<mtd::MockDisplaySupportProvider> mock_display_support_provider;
 
45
    EGLDisplay dpy;
 
46
    EGLSurface surf;
 
47
    mir::EglMock mock_egl;
 
48
};
 
49
 
 
50
namespace
 
51
{
 
52
struct HWCDummyLayer : public mga::HWCDefaultLayer
 
53
{
 
54
    HWCDummyLayer()
 
55
     : HWCDefaultLayer({})
 
56
    {
 
57
    }
 
58
};
 
59
}
 
60
 
 
61
TEST_F(HWC11Device, test_hwc_gles_set_empty_layerlist)
 
62
{
 
63
    using namespace testing;
 
64
 
 
65
    mga::HWC11Device device(mock_device, mock_organizer, mock_display_support_provider);
 
66
 
 
67
    mga::LayerList empty_list;
 
68
    EXPECT_CALL(*mock_organizer, native_list())
 
69
        .Times(1)
 
70
        .WillOnce(ReturnRef(empty_list));
 
71
    EXPECT_CALL(*mock_device, set_interface(mock_device.get(), HWC_NUM_DISPLAY_TYPES, _))
 
72
        .Times(1);
 
73
 
 
74
    device.commit_frame(dpy, surf);
 
75
 
 
76
    EXPECT_EQ(empty_list.size(), mock_device->display0_set_content.numHwLayers);
 
77
 
 
78
    EXPECT_EQ(-1, mock_device->display0_set_content.retireFenceFd);
 
79
}
 
80
 
 
81
TEST_F(HWC11Device, test_hwc_gles_set_gets_layerlist)
 
82
{
 
83
    using namespace testing;
 
84
 
 
85
    mga::HWC11Device device(mock_device, mock_organizer, mock_display_support_provider);
 
86
 
 
87
    mga::LayerList fb_list;
 
88
    fb_list.push_back(std::make_shared<HWCDummyLayer>());
 
89
 
 
90
    EXPECT_CALL(*mock_organizer, native_list())
 
91
        .Times(1)
 
92
        .WillOnce(ReturnRef(fb_list));
 
93
    EXPECT_CALL(*mock_device, set_interface(mock_device.get(), HWC_NUM_DISPLAY_TYPES, _))
 
94
        .Times(1);
 
95
 
 
96
    device.commit_frame(dpy, surf);
 
97
 
 
98
    EXPECT_EQ(fb_list.size(), mock_device->display0_set_content.numHwLayers);
 
99
}
 
100
 
 
101
TEST_F(HWC11Device, test_hwc_gles_set_error)
 
102
{
 
103
    using namespace testing;
 
104
 
 
105
    mga::HWC11Device device(mock_device, mock_organizer, mock_display_support_provider);
 
106
    mga::LayerList fb_list;
 
107
    fb_list.push_back(std::make_shared<HWCDummyLayer>());
 
108
 
 
109
    EXPECT_CALL(*mock_organizer, native_list())
 
110
        .Times(1)
 
111
        .WillOnce(ReturnRef(fb_list));
 
112
    EXPECT_CALL(*mock_device, set_interface(mock_device.get(), HWC_NUM_DISPLAY_TYPES, _))
 
113
        .Times(1)
 
114
        .WillOnce(Return(-1));
 
115
 
 
116
    EXPECT_THROW({
 
117
        device.commit_frame(dpy, surf);
 
118
    }, std::runtime_error);
 
119
}
 
120
 
 
121
TEST_F(HWC11Device, test_hwc_gles_commit_swapbuffers_failure)
 
122
{
 
123
    using namespace testing;
 
124
    EXPECT_CALL(mock_egl, eglSwapBuffers(dpy,surf))
 
125
        .Times(1)
 
126
        .WillOnce(Return(EGL_FALSE));
 
127
 
 
128
    mga::HWC11Device device(mock_device, mock_organizer, mock_display_support_provider);
 
129
 
 
130
    EXPECT_THROW({
 
131
        device.commit_frame(dpy, surf);
 
132
    }, std::runtime_error);
 
133
}
 
134
 
 
135
TEST_F(HWC11Device, test_hwc_gles_set_commits_via_swapbuffers_then_set)
 
136
{
 
137
    using namespace testing;
 
138
 
 
139
    mga::HWC11Device device(mock_device, mock_organizer, mock_display_support_provider);
 
140
 
 
141
    mga::LayerList fb_list;
 
142
    fb_list.push_back(std::make_shared<HWCDummyLayer>());
 
143
 
 
144
    //the order here is very important. eglSwapBuffers will alter the layerlist,
 
145
    //so it must come before assembling the data for set
 
146
    InSequence seq;
 
147
    EXPECT_CALL(mock_egl, eglSwapBuffers(dpy,surf))
 
148
        .Times(1);
 
149
    EXPECT_CALL(*mock_organizer, native_list())
 
150
        .Times(1)
 
151
        .WillOnce(ReturnRef(fb_list));
 
152
    EXPECT_CALL(*mock_device, set_interface(mock_device.get(), HWC_NUM_DISPLAY_TYPES, _))
 
153
        .Times(1);
 
154
 
 
155
    device.commit_frame(dpy, surf);
 
156
 
 
157
    EXPECT_EQ(fb_list.size(), mock_device->display0_set_content.numHwLayers);
 
158
}
 
159
 
 
160
TEST_F(HWC11Device, test_hwc_device_display_config)
 
161
{
 
162
    using namespace testing;
 
163
 
 
164
    unsigned int hwc_configs = 0xA1;
 
165
    EXPECT_CALL(*mock_device, getDisplayConfigs_interface(mock_device.get(),HWC_DISPLAY_PRIMARY,_,Pointee(1)))
 
166
        .Times(1)
 
167
        .WillOnce(DoAll(SetArgPointee<2>(hwc_configs), Return(0)));
 
168
 
 
169
    mga::HWC11Device device(mock_device, mock_organizer, mock_display_support_provider);
 
170
}
 
171
 
 
172
//apparently this can happen if the display is in the 'unplugged state'
 
173
TEST_F(HWC11Device, test_hwc_device_display_config_failure_throws)
 
174
{
 
175
    using namespace testing;
 
176
 
 
177
    EXPECT_CALL(*mock_device, getDisplayConfigs_interface(mock_device.get(),HWC_DISPLAY_PRIMARY,_,_))
 
178
        .Times(1)
 
179
        .WillOnce(Return(-1));
 
180
 
 
181
    EXPECT_THROW({
 
182
        mga::HWC11Device device(mock_device, mock_organizer, mock_display_support_provider);
 
183
    }, std::runtime_error);
 
184
}
 
185
 
 
186
namespace
 
187
{
 
188
static int const display_width = 180;
 
189
static int const display_height = 1010101;
 
190
 
 
191
static int display_attribute_handler(struct hwc_composer_device_1*, int, uint32_t,
 
192
                                     const uint32_t* attribute_list, int32_t* values)
 
193
{
 
194
    EXPECT_EQ(attribute_list[0], HWC_DISPLAY_WIDTH);
 
195
    EXPECT_EQ(attribute_list[1], HWC_DISPLAY_HEIGHT);
 
196
    EXPECT_EQ(attribute_list[2], HWC_DISPLAY_NO_ATTRIBUTE);
 
197
 
 
198
    values[0] = display_width;
 
199
    values[1] = display_height;
 
200
    return 0;
 
201
}
 
202
 
 
203
TEST_F(HWC11Device, test_hwc_device_display_width_height)
 
204
{
 
205
    using namespace testing;
 
206
 
 
207
    int hwc_configs = 0xA1;
 
208
    EXPECT_CALL(*mock_device, getDisplayConfigs_interface(mock_device.get(),HWC_DISPLAY_PRIMARY,_,_))
 
209
        .Times(1)
 
210
        .WillOnce(DoAll(SetArgPointee<2>(hwc_configs), Return(0)));
 
211
 
 
212
    mga::HWC11Device device(mock_device, mock_organizer, mock_display_support_provider);
 
213
 
 
214
    EXPECT_CALL(*mock_device, getDisplayAttributes_interface(mock_device.get(), HWC_DISPLAY_PRIMARY,hwc_configs,_,_))
 
215
        .Times(1)
 
216
        .WillOnce(Invoke(display_attribute_handler));
 
217
 
 
218
    auto size = device.display_size();
 
219
    EXPECT_EQ(size.width.as_uint32_t(),  static_cast<unsigned int>(display_width));
 
220
    EXPECT_EQ(size.height.as_uint32_t(), static_cast<unsigned int>(display_height));
 
221
}
 
222
}
 
223
 
 
224
TEST_F(HWC11Device, hwc_device_set_next_frontbuffer_adds_to_layerlist)
 
225
{
 
226
    std::shared_ptr<mga::AndroidBuffer> mock_buffer = std::make_shared<mtd::MockAndroidBuffer>();
 
227
    EXPECT_CALL(*this->mock_organizer, set_fb_target(mock_buffer))
 
228
        .Times(1);
 
229
 
 
230
    mga::HWC11Device device(mock_device, mock_organizer, mock_display_support_provider);
 
231
    device.set_next_frontbuffer(mock_buffer);
 
232
}
 
233
 
 
234
TEST_F(HWC11Device, hwc_device_set_next_frontbuffer_posts)
 
235
{
 
236
    std::shared_ptr<mga::AndroidBuffer> mock_buffer = std::make_shared<mtd::MockAndroidBuffer>();
 
237
    EXPECT_CALL(*this->mock_display_support_provider, set_next_frontbuffer(mock_buffer))
 
238
        .Times(1);
 
239
 
 
240
    mga::HWC11Device device(mock_device, mock_organizer, mock_display_support_provider);
 
241
    device.set_next_frontbuffer(mock_buffer);
 
242
}