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_EQ(HdiDeviceTest::hdiDevice_->GetScreenPowerStatus(screenId, dstatus), GRAPHIC_DISPLAY_SUCCESS);
84 EXPECT_EQ(HdiDeviceTest::hdiDevice_->SetScreenPowerStatus(screenId, dstatus), GRAPHIC_DISPLAY_SUCCESS);
85 EXPECT_EQ(HdiDeviceTest::hdiDevice_->GetScreenBacklight(screenId, screenLightLevel), GRAPHIC_DISPLAY_SUCCESS);
86 EXPECT_CALL(*hdiDeviceMock_,
87 SetScreenBacklight(_, _)).WillRepeatedly(testing::Return(GRAPHIC_DISPLAY_SUCCESS));
88 EXPECT_EQ(hdiDeviceMock_->SetScreenBacklight(screenId, screenLightLevel), GRAPHIC_DISPLAY_SUCCESS);
89 EXPECT_EQ(HdiDeviceTest::hdiDevice_->PrepareScreenLayers(screenId, needFlush), GRAPHIC_DISPLAY_SUCCESS);
90 std::vector<uint32_t> layersId;
91 std::vector<int32_t> types;
92 EXPECT_EQ(HdiDeviceTest::hdiDevice_->GetScreenCompChange(screenId, layersId, types), GRAPHIC_DISPLAY_SUCCESS);
93 BufferHandle *buffer = nullptr;
94 sptr<SyncFence> fence = nullptr;
95 uint32_t cacheIndex = 0;
96 EXPECT_EQ(HdiDeviceTest::hdiDevice_->SetScreenClientBuffer(screenId, buffer, cacheIndex, fence),
97 GRAPHIC_DISPLAY_PARAM_ERR);
98 buffer = new BufferHandle();
99 EXPECT_EQ(HdiDeviceTest::hdiDevice_->SetScreenClientBuffer(screenId, buffer, cacheIndex, fence),
100 GRAPHIC_DISPLAY_PARAM_ERR);
101 fence = new SyncFence(-1);
102 EXPECT_EQ(HdiDeviceTest::hdiDevice_->SetScreenClientBuffer(screenId, buffer, cacheIndex, fence),
103 GRAPHIC_DISPLAY_SUCCESS);
104 std::vector<GraphicIRect> damageRects = { {0, 0, 0, 0} };
105 EXPECT_EQ(HdiDeviceTest::hdiDevice_->SetScreenClientDamage(screenId, damageRects), GRAPHIC_DISPLAY_SUCCESS);
106 std::vector<GraphicColorGamut> gamuts;
107 EXPECT_CALL(*hdiDeviceMock_,
108 GetScreenSupportedColorGamuts(_, _)).WillRepeatedly(testing::Return(GRAPHIC_DISPLAY_SUCCESS));
109 EXPECT_EQ(hdiDeviceMock_->GetScreenSupportedColorGamuts(screenId, gamuts), GRAPHIC_DISPLAY_SUCCESS);
110 GraphicColorGamut gamut = GRAPHIC_COLOR_GAMUT_INVALID;
111 EXPECT_EQ(HdiDeviceTest::hdiDevice_->SetScreenColorGamut(screenId, gamut), GRAPHIC_DISPLAY_NOT_SUPPORT);
112 EXPECT_EQ(HdiDeviceTest::hdiDevice_->GetScreenColorGamut(screenId, gamut), GRAPHIC_DISPLAY_NOT_SUPPORT);
113 GraphicGamutMap gamutMap = GRAPHIC_GAMUT_MAP_CONSTANT;
114 EXPECT_EQ(HdiDeviceTest::hdiDevice_->SetScreenGamutMap(screenId, gamutMap), GRAPHIC_DISPLAY_NOT_SUPPORT);
115 EXPECT_EQ(HdiDeviceTest::hdiDevice_->GetScreenGamutMap(screenId, gamutMap), GRAPHIC_DISPLAY_NOT_SUPPORT);
116 std::vector<float> matrix = { 0.0 };
117 EXPECT_EQ(HdiDeviceTest::hdiDevice_->SetScreenColorTransform(screenId, matrix), GRAPHIC_DISPLAY_NOT_SUPPORT);
118 EXPECT_CALL(*hdiDeviceMock_,
119 Commit(_, _)).WillRepeatedly(testing::Return(GRAPHIC_DISPLAY_SUCCESS));
120 EXPECT_EQ(hdiDeviceMock_->Commit(screenId, fence), GRAPHIC_DISPLAY_SUCCESS);
121 }
122
123 /*
124 * Function: DeviceFuncs002
125 * Type: Function
126 * Rank: Important(3)
127 * EnvConditions: N/A
128 * CaseDescription: 1. call DeviceFuncs
129 * 2. check ret
130 */
131 HWTEST_F(HdiDeviceTest, DeviceFuncs002, Function | MediumTest| Level3)
132 {
133 uint32_t screenId = 1;
134 GraphicHDRCapability info;
135 EXPECT_CALL(*hdiDeviceMock_,
136 GetHDRCapabilityInfos(_, _)).WillRepeatedly(testing::Return(GRAPHIC_DISPLAY_SUCCESS));
137 EXPECT_EQ(hdiDeviceMock_->GetHDRCapabilityInfos(screenId, info), GRAPHIC_DISPLAY_SUCCESS);
138 std::vector<GraphicHDRMetadataKey> keys;
139 EXPECT_CALL(*hdiDeviceMock_,
140 GetSupportedMetaDataKey(_, _)).WillRepeatedly(testing::Return(GRAPHIC_DISPLAY_SUCCESS));
141 EXPECT_EQ(hdiDeviceMock_->GetSupportedMetaDataKey(screenId, keys), GRAPHIC_DISPLAY_SUCCESS);
142 }
143
144 /*
145 * Function: LayerFuncs001
146 * Type: Function
147 * Rank: Important(3)
148 * EnvConditions: N/A
149 * CaseDescription: 1. call LayerFuncs
150 * 2. check ret
151 */
152 HWTEST_F(HdiDeviceTest, LayerFuncs001, Function | MediumTest| Level3)
153 {
154 uint32_t screenId = 1, layerId = 0, zorder = 0;
155 GraphicLayerAlpha alpha;
156 EXPECT_EQ(HdiDeviceTest::hdiDevice_->SetLayerAlpha(screenId, layerId, alpha), GRAPHIC_DISPLAY_SUCCESS);
157 GraphicIRect layerRect = {0, 0, 0, 0};
158 EXPECT_EQ(HdiDeviceTest::hdiDevice_->SetLayerSize(screenId, layerId, layerRect), GRAPHIC_DISPLAY_SUCCESS);
159 GraphicTransformType type = GRAPHIC_ROTATE_NONE;
160 EXPECT_EQ(HdiDeviceTest::hdiDevice_->SetTransformMode(screenId, layerId, type), GRAPHIC_DISPLAY_SUCCESS);
161 std::vector<GraphicIRect> visibles = { {0, 0, 0, 0} };
162 EXPECT_EQ(HdiDeviceTest::hdiDevice_->SetLayerVisibleRegion(screenId, layerId, visibles), GRAPHIC_DISPLAY_SUCCESS);
163 std::vector<GraphicIRect> dirtyRegions = { {0, 0, 0, 0} };
164 EXPECT_EQ(HdiDeviceTest::hdiDevice_->SetLayerDirtyRegion(screenId, layerId, dirtyRegions),
165 GRAPHIC_DISPLAY_SUCCESS);
166 BufferHandle *handle = nullptr;
167 sptr<SyncFence> acquireFence = nullptr;
168 std::vector<uint32_t> deletingList = {};
169 uint32_t cacheIndex = INVALID_BUFFER_CACHE_INDEX;
170 GraphicLayerBuffer layerBuffer = {handle, cacheIndex, acquireFence, deletingList};
171 EXPECT_EQ(HdiDeviceTest::hdiDevice_->SetLayerBuffer(screenId, layerId, layerBuffer), GRAPHIC_DISPLAY_PARAM_ERR);
172 handle = new BufferHandle();
173 EXPECT_EQ(HdiDeviceTest::hdiDevice_->SetLayerBuffer(screenId, layerId, layerBuffer), GRAPHIC_DISPLAY_PARAM_ERR);
174 layerBuffer.acquireFence = new SyncFence(10);
175 EXPECT_EQ(HdiDeviceTest::hdiDevice_->SetLayerBuffer(screenId, layerId, layerBuffer), GRAPHIC_DISPLAY_PARAM_ERR);
176 layerBuffer.cacheIndex = 0;
177 EXPECT_CALL(*hdiDeviceMock_,
178 SetLayerBuffer(_, _, _)).WillRepeatedly(testing::Return(GRAPHIC_DISPLAY_SUCCESS));
179 EXPECT_EQ(hdiDeviceMock_->SetLayerBuffer(screenId, layerId, layerBuffer), GRAPHIC_DISPLAY_SUCCESS);
180 GraphicCompositionType cmpType = GRAPHIC_COMPOSITION_CLIENT;
181 EXPECT_EQ(HdiDeviceTest::hdiDevice_->SetLayerCompositionType(screenId, layerId, cmpType), GRAPHIC_DISPLAY_SUCCESS);
182 GraphicBlendType blendType = GRAPHIC_BLEND_NONE;
183 EXPECT_EQ(HdiDeviceTest::hdiDevice_->SetLayerBlendType(screenId, layerId, blendType), GRAPHIC_DISPLAY_SUCCESS);
184 GraphicIRect crop = {0, 0, 0, 0};
185 EXPECT_EQ(HdiDeviceTest::hdiDevice_->SetLayerCrop(screenId, layerId, crop), GRAPHIC_DISPLAY_SUCCESS);
186 EXPECT_EQ(HdiDeviceTest::hdiDevice_->SetLayerZorder(screenId, layerId, zorder), GRAPHIC_DISPLAY_SUCCESS);
187 bool isPreMulti = false;
188 EXPECT_EQ(HdiDeviceTest::hdiDevice_->SetLayerPreMulti(screenId, layerId, isPreMulti), GRAPHIC_DISPLAY_SUCCESS);
189 std::vector<float> matrix = { 0.0 };
190 EXPECT_EQ(HdiDeviceTest::hdiDevice_->SetLayerColorTransform(screenId, layerId, matrix),
191 GRAPHIC_DISPLAY_NOT_SUPPORT);
192 GraphicColorDataSpace colorSpace = GRAPHIC_COLOR_DATA_SPACE_UNKNOWN;
193 EXPECT_EQ(HdiDeviceTest::hdiDevice_->SetLayerColorDataSpace(screenId, layerId, colorSpace),
194 GRAPHIC_DISPLAY_NOT_SUPPORT);
195 EXPECT_EQ(HdiDeviceTest::hdiDevice_->GetLayerColorDataSpace(screenId, layerId, colorSpace),
196 GRAPHIC_DISPLAY_NOT_SUPPORT);
197 std::vector<GraphicHDRMetaData> metaData;
198 EXPECT_EQ(HdiDeviceTest::hdiDevice_->SetLayerMetaData(screenId, layerId, metaData), GRAPHIC_DISPLAY_NOT_SUPPORT);
199 GraphicHDRMetadataKey key = GRAPHIC_MATAKEY_RED_PRIMARY_X;
200 std::vector<uint8_t> metaDatas;
201 EXPECT_EQ(HdiDeviceTest::hdiDevice_->SetLayerMetaDataSet(screenId, layerId, key, metaDatas),
202 GRAPHIC_DISPLAY_NOT_SUPPORT);
203 GraphicExtDataHandle *extDataHandle = nullptr;
204 EXPECT_EQ(HdiDeviceTest::hdiDevice_->SetLayerTunnelHandle(screenId, layerId, extDataHandle),
205 GRAPHIC_DISPLAY_NOT_SUPPORT);
206 GraphicPresentTimestampType presentTimesType = GRAPHIC_DISPLAY_PTS_UNSUPPORTED;
207 EXPECT_EQ(HdiDeviceTest::hdiDevice_->GetSupportedPresentTimestampType(screenId, layerId, presentTimesType),
208 GRAPHIC_DISPLAY_NOT_SUPPORT);
209 }
210
211 /*
212 * Function: LayerFuncs002
213 * Type: Function
214 * Rank: Important(3)
215 * EnvConditions: N/A
216 * CaseDescription: 1. call LayerFuncs
217 * 2. check ret
218 */
219 HWTEST_F(HdiDeviceTest, LayerFuncs002, Function | MediumTest| Level3)
220 {
221 uint32_t screenId = 1, layerId = 0;
222 GraphicPresentTimestamp timestamp;
223 EXPECT_EQ(HdiDeviceTest::hdiDevice_->GetPresentTimestamp(screenId, layerId, timestamp),
224 GRAPHIC_DISPLAY_NOT_SUPPORT);
225 uint32_t layerMask = 0;
226 EXPECT_EQ(HdiDeviceTest::hdiDevice_->SetLayerMaskInfo(screenId, layerId, layerMask), GRAPHIC_DISPLAY_SUCCESS);
227 GraphicLayerInfo layerInfo;
228 uint32_t cacheCount = 1;
229 EXPECT_EQ(HdiDeviceTest::hdiDevice_->CreateLayer(screenId, layerInfo, cacheCount, layerId),
230 GRAPHIC_DISPLAY_FAILURE);
231 std::vector<std::string> valueRet = HdiDeviceTest::hdiDevice_->GetSupportedLayerPerFrameParameterKey();
232 const std::string validKey = "ArsrDoEnhance";
233 if (std::find(valueRet.begin(), valueRet.end(), validKey) != valueRet.end()) {
234 const std::vector<int8_t> valueBlob{static_cast<int8_t>(1)};
235 EXPECT_EQ(HdiDeviceTest::hdiDevice_->SetLayerPerFrameParameter(screenId, layerId, validKey, valueBlob),
236 GRAPHIC_DISPLAY_FAILURE);
237 }
238 EXPECT_EQ(HdiDeviceTest::hdiDevice_->CloseLayer(screenId, layerId), GRAPHIC_DISPLAY_FAILURE);
239 }
240 } // namespace
241 } // namespace Rosen
242 } // namespace OHOS