1 /*
2 * Copyright (c) 2021 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include "hdi_device.h"
17 #include "mock_hdi_device.h"
18 #include <gtest/gtest.h>
19
20 using namespace testing;
21 using namespace testing::ext;
22
23 namespace OHOS {
24 namespace Rosen {
25 class HdiDeviceTest : public testing::Test {
26 public:
27 static void SetUpTestCase();
28 static void TearDownTestCase();
29
30 static inline HdiDevice* hdiDevice_ = nullptr;
31 static inline Mock::HdiDeviceMock* hdiDeviceMock_;
32 };
33
SetUpTestCase()34 void HdiDeviceTest::SetUpTestCase()
35 {
36 hdiDevice_ = HdiDevice::GetInstance();
37 hdiDeviceMock_ = Mock::HdiDeviceMock::GetInstance();
38 }
39
TearDownTestCase()40 void HdiDeviceTest::TearDownTestCase()
41 {
42 hdiDevice_ = nullptr;
43 hdiDeviceMock_ = nullptr;
44 }
45
46 namespace {
47 /*
48 * Function: DeviceFuncs001
49 * Type: Function
50 * Rank: Important(3)
51 * EnvConditions: N/A
52 * CaseDescription: 1. call DeviceFuncs
53 * 2. check ret
54 */
55 HWTEST_F(HdiDeviceTest, DeviceFuncs001, Function | MediumTest| Level3)
56 {
57 EXPECT_EQ(HdiDeviceTest::hdiDevice_->RegHotPlugCallback(nullptr, nullptr), GRAPHIC_DISPLAY_SUCCESS);
58 uint32_t screenId = 1, screenModeId = 0, screenLightLevel = 0;
59 EXPECT_EQ(HdiDeviceTest::hdiDevice_->RegScreenVBlankCallback(screenId, nullptr, nullptr),
60 GRAPHIC_DISPLAY_SUCCESS);
61 bool enabled = false, needFlush = false;
62 EXPECT_EQ(HdiDeviceTest::hdiDevice_->SetScreenVsyncEnabled(screenId, enabled), GRAPHIC_DISPLAY_SUCCESS);
63 uint32_t pid = 1;
64 uint64_t pvalue = 0;
65 EXPECT_CALL(*hdiDeviceMock_,
66 GetDisplayProperty(_, _, _)).WillRepeatedly(testing::Return(GRAPHIC_DISPLAY_SUCCESS));
67 EXPECT_EQ(hdiDeviceMock_->GetDisplayProperty(screenId, pid, pvalue), GRAPHIC_DISPLAY_SUCCESS);
68 GraphicDisplayCapability dcpInfo;
69 EXPECT_CALL(*hdiDeviceMock_,
70 GetScreenCapability(_, _)).WillRepeatedly(testing::Return(GRAPHIC_DISPLAY_SUCCESS));
71 EXPECT_EQ(hdiDeviceMock_->GetScreenCapability(screenId, dcpInfo), GRAPHIC_DISPLAY_SUCCESS);
72 std::vector<GraphicDisplayModeInfo> dmodes;
73 EXPECT_EQ(HdiDeviceTest::hdiDevice_->GetScreenSupportedModes(screenId, dmodes), GRAPHIC_DISPLAY_SUCCESS);
74 EXPECT_EQ(HdiDeviceTest::hdiDevice_->GetScreenMode(screenId, screenModeId), GRAPHIC_DISPLAY_SUCCESS);
75 EXPECT_EQ(HdiDeviceTest::hdiDevice_->SetScreenMode(screenId, screenModeId), GRAPHIC_DISPLAY_SUCCESS);
76 uint32_t width = 1080;
77 uint32_t height = 1920;
78 EXPECT_CALL(*hdiDeviceMock_,
79 SetScreenOverlayResolution(_, _, _)).WillRepeatedly(testing::Return(GRAPHIC_DISPLAY_SUCCESS));
80 EXPECT_EQ(hdiDeviceMock_->SetScreenOverlayResolution(screenId, width, height),
81 GRAPHIC_DISPLAY_SUCCESS);
82 GraphicDispPowerStatus dstatus = GRAPHIC_POWER_STATUS_ON;
83 EXPECT_CALL(*hdiDeviceMock_,
84 SetScreenPowerStatus(_, _)).WillRepeatedly(testing::Return(GRAPHIC_DISPLAY_SUCCESS));
85 EXPECT_EQ(hdiDeviceMock_->SetScreenPowerStatus(screenId, dstatus), GRAPHIC_DISPLAY_SUCCESS);
86 EXPECT_CALL(*hdiDeviceMock_,
87 GetScreenPowerStatus(_, _)).WillRepeatedly(testing::Return(GRAPHIC_DISPLAY_SUCCESS));
88 EXPECT_EQ(hdiDeviceMock_->GetScreenPowerStatus(screenId, dstatus), GRAPHIC_DISPLAY_SUCCESS);
89 EXPECT_CALL(*hdiDeviceMock_,
90 GetScreenBacklight(_, _)).WillRepeatedly(testing::Return(GRAPHIC_DISPLAY_SUCCESS));
91 EXPECT_EQ(hdiDeviceMock_->GetScreenBacklight(screenId, screenLightLevel), GRAPHIC_DISPLAY_SUCCESS);
92 EXPECT_CALL(*hdiDeviceMock_,
93 SetScreenBacklight(_, _)).WillRepeatedly(testing::Return(GRAPHIC_DISPLAY_SUCCESS));
94 EXPECT_EQ(hdiDeviceMock_->SetScreenBacklight(screenId, screenLightLevel), GRAPHIC_DISPLAY_SUCCESS);
95 EXPECT_CALL(*hdiDeviceMock_,
96 PrepareScreenLayers(_, _)).WillRepeatedly(testing::Return(GRAPHIC_DISPLAY_SUCCESS));
97 EXPECT_EQ(hdiDeviceMock_->PrepareScreenLayers(screenId, needFlush), GRAPHIC_DISPLAY_SUCCESS);
98 std::vector<uint32_t> layersId;
99 std::vector<int32_t> types;
100 EXPECT_EQ(HdiDeviceTest::hdiDevice_->GetScreenCompChange(screenId, layersId, types), GRAPHIC_DISPLAY_SUCCESS);
101 BufferHandle *buffer = nullptr;
102 sptr<SyncFence> fence = nullptr;
103 uint32_t cacheIndex = 0;
104 EXPECT_EQ(HdiDeviceTest::hdiDevice_->SetScreenClientBuffer(screenId, buffer, cacheIndex, fence),
105 GRAPHIC_DISPLAY_PARAM_ERR);
106 buffer = new BufferHandle();
107 EXPECT_EQ(HdiDeviceTest::hdiDevice_->SetScreenClientBuffer(screenId, buffer, cacheIndex, fence),
108 GRAPHIC_DISPLAY_PARAM_ERR);
109 fence = new SyncFence(-1);
110 EXPECT_EQ(HdiDeviceTest::hdiDevice_->SetScreenClientBuffer(screenId, buffer, cacheIndex, fence),
111 GRAPHIC_DISPLAY_SUCCESS);
112 std::vector<GraphicIRect> damageRects = { {0, 0, 0, 0} };
113 EXPECT_EQ(HdiDeviceTest::hdiDevice_->SetScreenClientDamage(screenId, damageRects), GRAPHIC_DISPLAY_SUCCESS);
114 std::vector<GraphicColorGamut> gamuts;
115 EXPECT_CALL(*hdiDeviceMock_,
116 GetScreenSupportedColorGamuts(_, _)).WillRepeatedly(testing::Return(GRAPHIC_DISPLAY_SUCCESS));
117 EXPECT_EQ(hdiDeviceMock_->GetScreenSupportedColorGamuts(screenId, gamuts), GRAPHIC_DISPLAY_SUCCESS);
118 GraphicColorGamut gamut = GRAPHIC_COLOR_GAMUT_INVALID;
119 EXPECT_EQ(HdiDeviceTest::hdiDevice_->SetScreenColorGamut(screenId, gamut), GRAPHIC_DISPLAY_NOT_SUPPORT);
120 EXPECT_EQ(HdiDeviceTest::hdiDevice_->GetScreenColorGamut(screenId, gamut), GRAPHIC_DISPLAY_NOT_SUPPORT);
121 GraphicGamutMap gamutMap = GRAPHIC_GAMUT_MAP_CONSTANT;
122 EXPECT_EQ(HdiDeviceTest::hdiDevice_->SetScreenGamutMap(screenId, gamutMap), GRAPHIC_DISPLAY_NOT_SUPPORT);
123 EXPECT_EQ(HdiDeviceTest::hdiDevice_->GetScreenGamutMap(screenId, gamutMap), GRAPHIC_DISPLAY_NOT_SUPPORT);
124 std::vector<float> matrix = { 0.0 };
125 EXPECT_EQ(HdiDeviceTest::hdiDevice_->SetScreenColorTransform(screenId, matrix), GRAPHIC_DISPLAY_NOT_SUPPORT);
126 EXPECT_CALL(*hdiDeviceMock_,
127 Commit(_, _)).WillRepeatedly(testing::Return(GRAPHIC_DISPLAY_SUCCESS));
128 EXPECT_EQ(hdiDeviceMock_->Commit(screenId, fence), GRAPHIC_DISPLAY_SUCCESS);
129 }
130
131 /*
132 * Function: DeviceFuncs002
133 * Type: Function
134 * Rank: Important(3)
135 * EnvConditions: N/A
136 * CaseDescription: 1. call DeviceFuncs
137 * 2. check ret
138 */
139 HWTEST_F(HdiDeviceTest, DeviceFuncs002, Function | MediumTest| Level3)
140 {
141 uint32_t screenId = 1;
142 GraphicHDRCapability info;
143 EXPECT_CALL(*hdiDeviceMock_,
144 GetHDRCapabilityInfos(_, _)).WillRepeatedly(testing::Return(GRAPHIC_DISPLAY_SUCCESS));
145 EXPECT_EQ(hdiDeviceMock_->GetHDRCapabilityInfos(screenId, info), GRAPHIC_DISPLAY_SUCCESS);
146 std::vector<GraphicHDRMetadataKey> keys;
147 EXPECT_CALL(*hdiDeviceMock_,
148 GetSupportedMetaDataKey(_, _)).WillRepeatedly(testing::Return(GRAPHIC_DISPLAY_SUCCESS));
149 EXPECT_EQ(hdiDeviceMock_->GetSupportedMetaDataKey(screenId, keys), GRAPHIC_DISPLAY_SUCCESS);
150 }
151
152 /*
153 * Function: LayerFuncs001
154 * Type: Function
155 * Rank: Important(3)
156 * EnvConditions: N/A
157 * CaseDescription: 1. call LayerFuncs
158 * 2. check ret
159 */
160 HWTEST_F(HdiDeviceTest, LayerFuncs001, Function | MediumTest| Level3)
161 {
162 uint32_t screenId = 1, layerId = 0, zorder = 0;
163 GraphicLayerAlpha alpha;
164 EXPECT_EQ(HdiDeviceTest::hdiDevice_->SetLayerAlpha(screenId, layerId, alpha), GRAPHIC_DISPLAY_SUCCESS);
165 GraphicIRect layerRect = {0, 0, 0, 0};
166 EXPECT_EQ(HdiDeviceTest::hdiDevice_->SetLayerSize(screenId, layerId, layerRect), GRAPHIC_DISPLAY_SUCCESS);
167 GraphicTransformType type = GRAPHIC_ROTATE_NONE;
168 EXPECT_EQ(HdiDeviceTest::hdiDevice_->SetTransformMode(screenId, layerId, type), GRAPHIC_DISPLAY_SUCCESS);
169 std::vector<GraphicIRect> visibles = { {0, 0, 0, 0} };
170 EXPECT_EQ(HdiDeviceTest::hdiDevice_->SetLayerVisibleRegion(screenId, layerId, visibles), GRAPHIC_DISPLAY_SUCCESS);
171 std::vector<GraphicIRect> dirtyRegions = { {0, 0, 0, 0} };
172 EXPECT_EQ(HdiDeviceTest::hdiDevice_->SetLayerDirtyRegion(screenId, layerId, dirtyRegions),
173 GRAPHIC_DISPLAY_SUCCESS);
174 BufferHandle *handle = nullptr;
175 sptr<SyncFence> acquireFence = nullptr;
176 std::vector<uint32_t> deletingList = {};
177 uint32_t cacheIndex = INVALID_BUFFER_CACHE_INDEX;
178 GraphicLayerBuffer layerBuffer = {handle, cacheIndex, acquireFence, deletingList};
179 EXPECT_EQ(HdiDeviceTest::hdiDevice_->SetLayerBuffer(screenId, layerId, layerBuffer), GRAPHIC_DISPLAY_PARAM_ERR);
180 handle = new BufferHandle();
181 EXPECT_EQ(HdiDeviceTest::hdiDevice_->SetLayerBuffer(screenId, layerId, layerBuffer), GRAPHIC_DISPLAY_PARAM_ERR);
182 layerBuffer.acquireFence = new SyncFence(10);
183 EXPECT_EQ(HdiDeviceTest::hdiDevice_->SetLayerBuffer(screenId, layerId, layerBuffer), GRAPHIC_DISPLAY_PARAM_ERR);
184 layerBuffer.cacheIndex = 0;
185 EXPECT_CALL(*hdiDeviceMock_,
186 SetLayerBuffer(_, _, _)).WillRepeatedly(testing::Return(GRAPHIC_DISPLAY_SUCCESS));
187 EXPECT_EQ(hdiDeviceMock_->SetLayerBuffer(screenId, layerId, layerBuffer), GRAPHIC_DISPLAY_SUCCESS);
188 GraphicCompositionType cmpType = GRAPHIC_COMPOSITION_CLIENT;
189 EXPECT_EQ(HdiDeviceTest::hdiDevice_->SetLayerCompositionType(screenId, layerId, cmpType), GRAPHIC_DISPLAY_SUCCESS);
190 GraphicBlendType blendType = GRAPHIC_BLEND_NONE;
191 EXPECT_EQ(HdiDeviceTest::hdiDevice_->SetLayerBlendType(screenId, layerId, blendType), GRAPHIC_DISPLAY_SUCCESS);
192 GraphicIRect crop = {0, 0, 0, 0};
193 EXPECT_EQ(HdiDeviceTest::hdiDevice_->SetLayerCrop(screenId, layerId, crop), GRAPHIC_DISPLAY_SUCCESS);
194 EXPECT_EQ(HdiDeviceTest::hdiDevice_->SetLayerZorder(screenId, layerId, zorder), GRAPHIC_DISPLAY_SUCCESS);
195 bool isPreMulti = false;
196 EXPECT_EQ(HdiDeviceTest::hdiDevice_->SetLayerPreMulti(screenId, layerId, isPreMulti), GRAPHIC_DISPLAY_SUCCESS);
197 std::vector<float> matrix = { 0.0 };
198 EXPECT_EQ(HdiDeviceTest::hdiDevice_->SetLayerColorTransform(screenId, layerId, matrix),
199 GRAPHIC_DISPLAY_NOT_SUPPORT);
200 GraphicColorDataSpace colorSpace = GRAPHIC_COLOR_DATA_SPACE_UNKNOWN;
201 EXPECT_EQ(HdiDeviceTest::hdiDevice_->SetLayerColorDataSpace(screenId, layerId, colorSpace),
202 GRAPHIC_DISPLAY_NOT_SUPPORT);
203 EXPECT_EQ(HdiDeviceTest::hdiDevice_->GetLayerColorDataSpace(screenId, layerId, colorSpace),
204 GRAPHIC_DISPLAY_NOT_SUPPORT);
205 std::vector<GraphicHDRMetaData> metaData;
206 EXPECT_EQ(HdiDeviceTest::hdiDevice_->SetLayerMetaData(screenId, layerId, metaData), GRAPHIC_DISPLAY_NOT_SUPPORT);
207 GraphicHDRMetadataKey key = GRAPHIC_MATAKEY_RED_PRIMARY_X;
208 std::vector<uint8_t> metaDatas;
209 EXPECT_EQ(HdiDeviceTest::hdiDevice_->SetLayerMetaDataSet(screenId, layerId, key, metaDatas),
210 GRAPHIC_DISPLAY_NOT_SUPPORT);
211 GraphicExtDataHandle *extDataHandle = nullptr;
212 EXPECT_EQ(HdiDeviceTest::hdiDevice_->SetLayerTunnelHandle(screenId, layerId, extDataHandle),
213 GRAPHIC_DISPLAY_NOT_SUPPORT);
214 GraphicPresentTimestampType presentTimesType = GRAPHIC_DISPLAY_PTS_UNSUPPORTED;
215 EXPECT_EQ(HdiDeviceTest::hdiDevice_->GetSupportedPresentTimestampType(screenId, layerId, presentTimesType),
216 GRAPHIC_DISPLAY_NOT_SUPPORT);
217 }
218
219 /*
220 * Function: LayerFuncs002
221 * Type: Function
222 * Rank: Important(3)
223 * EnvConditions: N/A
224 * CaseDescription: 1. call LayerFuncs
225 * 2. check ret
226 */
227 HWTEST_F(HdiDeviceTest, LayerFuncs002, Function | MediumTest| Level3)
228 {
229 uint32_t screenId = 1, layerId = 0;
230 GraphicPresentTimestamp timestamp;
231 EXPECT_EQ(HdiDeviceTest::hdiDevice_->GetPresentTimestamp(screenId, layerId, timestamp),
232 GRAPHIC_DISPLAY_NOT_SUPPORT);
233 uint32_t layerMask = 0;
234 EXPECT_EQ(HdiDeviceTest::hdiDevice_->SetLayerMaskInfo(screenId, layerId, layerMask), GRAPHIC_DISPLAY_SUCCESS);
235 GraphicLayerInfo layerInfo;
236 uint32_t cacheCount = 1;
237 EXPECT_EQ(HdiDeviceTest::hdiDevice_->CreateLayer(screenId, layerInfo, cacheCount, layerId),
238 GRAPHIC_DISPLAY_FAILURE);
239 std::vector<std::string> valueRet = HdiDeviceTest::hdiDevice_->GetSupportedLayerPerFrameParameterKey();
240 const std::string validKey = "ArsrDoEnhance";
241 if (std::find(valueRet.begin(), valueRet.end(), validKey) != valueRet.end()) {
242 const std::vector<int8_t> valueBlob{static_cast<int8_t>(1)};
243 EXPECT_EQ(HdiDeviceTest::hdiDevice_->SetLayerPerFrameParameter(screenId, layerId, validKey, valueBlob),
244 GRAPHIC_DISPLAY_FAILURE);
245 }
246 EXPECT_EQ(HdiDeviceTest::hdiDevice_->CloseLayer(screenId, layerId), GRAPHIC_DISPLAY_FAILURE);
247 }
248 } // namespace
249 } // namespace Rosen
250 } // namespace OHOS