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 <gtest/gtest.h>
18
19 using namespace testing;
20 using namespace testing::ext;
21
22 namespace OHOS {
23 namespace Rosen {
24 class HdiDeviceTest : public testing::Test {
25 public:
26 static void SetUpTestCase();
27 static void TearDownTestCase();
28
29 static inline HdiDevice* hdiDevice_ = nullptr;
30 };
31
SetUpTestCase()32 void HdiDeviceTest::SetUpTestCase()
33 {
34 hdiDevice_ = HdiDevice::GetInstance();
35 }
36
TearDownTestCase()37 void HdiDeviceTest::TearDownTestCase()
38 {
39 hdiDevice_ = nullptr;
40 }
41
42 namespace {
43 /*
44 * Function: DeviceFuncs001
45 * Type: Function
46 * Rank: Important(3)
47 * EnvConditions: N/A
48 * CaseDescription: 1. call DeviceFuncs
49 * 2. check ret
50 */
51 HWTEST_F(HdiDeviceTest, DeviceFuncs001, Function | MediumTest| Level3)
52 {
53 ASSERT_EQ(HdiDeviceTest::hdiDevice_->RegHotPlugCallback(nullptr, nullptr), GRAPHIC_DISPLAY_SUCCESS);
54 uint32_t screenId = 1, screenModeId = 0, screenLightLevel = 0;
55 ASSERT_EQ(HdiDeviceTest::hdiDevice_->RegScreenVBlankCallback(screenId, nullptr, nullptr),
56 GRAPHIC_DISPLAY_SUCCESS);
57 bool enabled = false, needFlush = false;
58 ASSERT_EQ(HdiDeviceTest::hdiDevice_->SetScreenVsyncEnabled(screenId, enabled), GRAPHIC_DISPLAY_SUCCESS);
59 uint32_t pid = 1;
60 uint64_t pvalue = 0;
61 EXPECT_EQ(HdiDeviceTest::hdiDevice_->GetDisplayProperty(screenId, pid, pvalue), GRAPHIC_DISPLAY_SUCCESS);
62 GraphicDisplayCapability dcpInfo;
63 ASSERT_EQ(HdiDeviceTest::hdiDevice_->GetScreenCapability(screenId, dcpInfo), GRAPHIC_DISPLAY_SUCCESS);
64 std::vector<GraphicDisplayModeInfo> dmodes;
65 ASSERT_EQ(HdiDeviceTest::hdiDevice_->GetScreenSupportedModes(screenId, dmodes), GRAPHIC_DISPLAY_SUCCESS);
66 ASSERT_EQ(HdiDeviceTest::hdiDevice_->GetScreenMode(screenId, screenModeId), GRAPHIC_DISPLAY_SUCCESS);
67 ASSERT_EQ(HdiDeviceTest::hdiDevice_->SetScreenMode(screenId, screenModeId), GRAPHIC_DISPLAY_SUCCESS);
68 uint32_t width = 1080;
69 uint32_t height = 1920;
70 ASSERT_EQ(HdiDeviceTest::hdiDevice_->SetScreenOverlayResolution(screenId, width, height), GRAPHIC_DISPLAY_SUCCESS);
71 GraphicDispPowerStatus dstatus = GRAPHIC_POWER_STATUS_ON;
72 ASSERT_EQ(HdiDeviceTest::hdiDevice_->GetScreenPowerStatus(screenId, dstatus), GRAPHIC_DISPLAY_SUCCESS);
73 ASSERT_EQ(HdiDeviceTest::hdiDevice_->SetScreenPowerStatus(screenId, dstatus), GRAPHIC_DISPLAY_SUCCESS);
74 ASSERT_EQ(HdiDeviceTest::hdiDevice_->GetScreenBacklight(screenId, screenLightLevel), GRAPHIC_DISPLAY_SUCCESS);
75 ASSERT_EQ(HdiDeviceTest::hdiDevice_->SetScreenBacklight(screenId, screenLightLevel), GRAPHIC_DISPLAY_SUCCESS);
76 ASSERT_EQ(HdiDeviceTest::hdiDevice_->PrepareScreenLayers(screenId, needFlush), GRAPHIC_DISPLAY_SUCCESS);
77 std::vector<uint32_t> layersId;
78 std::vector<int32_t> types;
79 ASSERT_EQ(HdiDeviceTest::hdiDevice_->GetScreenCompChange(screenId, layersId, types), GRAPHIC_DISPLAY_SUCCESS);
80 BufferHandle *buffer = nullptr;
81 sptr<SyncFence> fence = nullptr;
82 uint32_t cacheIndex = 0;
83 ASSERT_EQ(HdiDeviceTest::hdiDevice_->SetScreenClientBuffer(screenId, buffer, cacheIndex, fence),
84 GRAPHIC_DISPLAY_NULL_PTR);
85 buffer = new BufferHandle();
86 ASSERT_EQ(HdiDeviceTest::hdiDevice_->SetScreenClientBuffer(screenId, buffer, cacheIndex, fence),
87 GRAPHIC_DISPLAY_NULL_PTR);
88 fence = new SyncFence(-1);
89 ASSERT_EQ(HdiDeviceTest::hdiDevice_->SetScreenClientBuffer(screenId, buffer, cacheIndex, fence),
90 GRAPHIC_DISPLAY_SUCCESS);
91 std::vector<GraphicIRect> damageRects = { {0, 0, 0, 0} };
92 ASSERT_EQ(HdiDeviceTest::hdiDevice_->SetScreenClientDamage(screenId, damageRects), GRAPHIC_DISPLAY_SUCCESS);
93 std::vector<GraphicColorGamut> gamuts;
94 ASSERT_EQ(HdiDeviceTest::hdiDevice_->GetScreenSupportedColorGamuts(screenId, gamuts), GRAPHIC_DISPLAY_NOT_SUPPORT);
95 GraphicColorGamut gamut = GRAPHIC_COLOR_GAMUT_INVALID;
96 ASSERT_EQ(HdiDeviceTest::hdiDevice_->SetScreenColorGamut(screenId, gamut), GRAPHIC_DISPLAY_NOT_SUPPORT);
97 ASSERT_EQ(HdiDeviceTest::hdiDevice_->GetScreenColorGamut(screenId, gamut), GRAPHIC_DISPLAY_NOT_SUPPORT);
98 GraphicGamutMap gamutMap = GRAPHIC_GAMUT_MAP_CONSTANT;
99 ASSERT_EQ(HdiDeviceTest::hdiDevice_->SetScreenGamutMap(screenId, gamutMap), GRAPHIC_DISPLAY_NOT_SUPPORT);
100 ASSERT_EQ(HdiDeviceTest::hdiDevice_->GetScreenGamutMap(screenId, gamutMap), GRAPHIC_DISPLAY_NOT_SUPPORT);
101 std::vector<float> matrix = { 0.0 };
102 ASSERT_EQ(HdiDeviceTest::hdiDevice_->SetScreenColorTransform(screenId, matrix), GRAPHIC_DISPLAY_NOT_SUPPORT);
103 }
104
105 /*
106 * Function: DeviceFuncs002
107 * Type: Function
108 * Rank: Important(3)
109 * EnvConditions: N/A
110 * CaseDescription: 1. call DeviceFuncs
111 * 2. check ret
112 */
113 HWTEST_F(HdiDeviceTest, DeviceFuncs002, Function | MediumTest| Level3)
114 {
115 uint32_t screenId = 1;
116 GraphicHDRCapability info;
117 ASSERT_EQ(HdiDeviceTest::hdiDevice_->GetHDRCapabilityInfos(screenId, info), GRAPHIC_DISPLAY_NOT_SUPPORT);
118 std::vector<GraphicHDRMetadataKey> keys;
119 ASSERT_EQ(HdiDeviceTest::hdiDevice_->GetSupportedMetaDataKey(screenId, keys), GRAPHIC_DISPLAY_NOT_SUPPORT);
120 }
121
122 /*
123 * Function: LayerFuncs001
124 * Type: Function
125 * Rank: Important(3)
126 * EnvConditions: N/A
127 * CaseDescription: 1. call LayerFuncs
128 * 2. check ret
129 */
130 HWTEST_F(HdiDeviceTest, LayerFuncs001, Function | MediumTest| Level3)
131 {
132 uint32_t screenId = 1, layerId = 0, zorder = 0;
133 GraphicLayerAlpha alpha;
134 ASSERT_EQ(HdiDeviceTest::hdiDevice_->SetLayerAlpha(screenId, layerId, alpha), GRAPHIC_DISPLAY_SUCCESS);
135 GraphicIRect layerRect = {0, 0, 0, 0};
136 ASSERT_EQ(HdiDeviceTest::hdiDevice_->SetLayerSize(screenId, layerId, layerRect), GRAPHIC_DISPLAY_SUCCESS);
137 GraphicTransformType type = GRAPHIC_ROTATE_NONE;
138 ASSERT_EQ(HdiDeviceTest::hdiDevice_->SetTransformMode(screenId, layerId, type), GRAPHIC_DISPLAY_SUCCESS);
139 std::vector<GraphicIRect> visibles = { {0, 0, 0, 0} };
140 ASSERT_EQ(HdiDeviceTest::hdiDevice_->SetLayerVisibleRegion(screenId, layerId, visibles), GRAPHIC_DISPLAY_SUCCESS);
141 std::vector<GraphicIRect> dirtyRegions = { {0, 0, 0, 0} };
142 ASSERT_EQ(HdiDeviceTest::hdiDevice_->SetLayerDirtyRegion(screenId, layerId, dirtyRegions),
143 GRAPHIC_DISPLAY_SUCCESS);
144 BufferHandle *handle = nullptr;
145 sptr<SyncFence> acquireFence = nullptr;
146 std::vector<uint32_t> deletingList = {};
147 uint32_t cacheIndex = 0;
148 GraphicLayerBuffer layerBuffer = {handle, cacheIndex, acquireFence, deletingList};
149 ASSERT_EQ(HdiDeviceTest::hdiDevice_->SetLayerBuffer(screenId, layerId, layerBuffer), GRAPHIC_DISPLAY_NULL_PTR);
150 GraphicCompositionType cmpType = GRAPHIC_COMPOSITION_CLIENT;
151 ASSERT_EQ(HdiDeviceTest::hdiDevice_->SetLayerCompositionType(screenId, layerId, cmpType), GRAPHIC_DISPLAY_SUCCESS);
152 GraphicBlendType blendType = GRAPHIC_BLEND_NONE;
153 ASSERT_EQ(HdiDeviceTest::hdiDevice_->SetLayerBlendType(screenId, layerId, blendType), GRAPHIC_DISPLAY_SUCCESS);
154 GraphicIRect crop = {0, 0, 0, 0};
155 ASSERT_EQ(HdiDeviceTest::hdiDevice_->SetLayerCrop(screenId, layerId, crop), GRAPHIC_DISPLAY_SUCCESS);
156 ASSERT_EQ(HdiDeviceTest::hdiDevice_->SetLayerZorder(screenId, layerId, zorder), GRAPHIC_DISPLAY_SUCCESS);
157 bool isPreMulti = false;
158 ASSERT_EQ(HdiDeviceTest::hdiDevice_->SetLayerPreMulti(screenId, layerId, isPreMulti), GRAPHIC_DISPLAY_SUCCESS);
159 std::vector<float> matrix = { 0.0 };
160 ASSERT_EQ(HdiDeviceTest::hdiDevice_->SetLayerColorTransform(screenId, layerId, matrix),
161 GRAPHIC_DISPLAY_NOT_SUPPORT);
162 GraphicColorDataSpace colorSpace = GRAPHIC_COLOR_DATA_SPACE_UNKNOWN;
163 ASSERT_EQ(HdiDeviceTest::hdiDevice_->SetLayerColorDataSpace(screenId, layerId, colorSpace),
164 GRAPHIC_DISPLAY_NOT_SUPPORT);
165 ASSERT_EQ(HdiDeviceTest::hdiDevice_->GetLayerColorDataSpace(screenId, layerId, colorSpace),
166 GRAPHIC_DISPLAY_NOT_SUPPORT);
167 std::vector<GraphicHDRMetaData> metaData;
168 ASSERT_EQ(HdiDeviceTest::hdiDevice_->SetLayerMetaData(screenId, layerId, metaData), GRAPHIC_DISPLAY_NOT_SUPPORT);
169 GraphicHDRMetadataKey key = GRAPHIC_MATAKEY_RED_PRIMARY_X;
170 std::vector<uint8_t> metaDatas;
171 ASSERT_EQ(HdiDeviceTest::hdiDevice_->SetLayerMetaDataSet(screenId, layerId, key, metaDatas),
172 GRAPHIC_DISPLAY_NOT_SUPPORT);
173 GraphicExtDataHandle *extDataHandle = nullptr;
174 ASSERT_EQ(HdiDeviceTest::hdiDevice_->SetLayerTunnelHandle(screenId, layerId, extDataHandle),
175 GRAPHIC_DISPLAY_NOT_SUPPORT);
176 GraphicPresentTimestampType presentTimesType = GRAPHIC_DISPLAY_PTS_UNSUPPORTED;
177 ASSERT_EQ(HdiDeviceTest::hdiDevice_->GetSupportedPresentTimestampType(screenId, layerId, presentTimesType),
178 GRAPHIC_DISPLAY_NOT_SUPPORT);
179 }
180
181 /*
182 * Function: LayerFuncs002
183 * Type: Function
184 * Rank: Important(3)
185 * EnvConditions: N/A
186 * CaseDescription: 1. call LayerFuncs
187 * 2. check ret
188 */
189 HWTEST_F(HdiDeviceTest, LayerFuncs002, Function | MediumTest| Level3)
190 {
191 uint32_t screenId = 1, layerId = 0;
192 GraphicPresentTimestamp timestamp;
193 ASSERT_EQ(HdiDeviceTest::hdiDevice_->GetPresentTimestamp(screenId, layerId, timestamp),
194 GRAPHIC_DISPLAY_NOT_SUPPORT);
195 uint32_t layerMask = 0;
196 ASSERT_EQ(HdiDeviceTest::hdiDevice_->SetLayerMaskInfo(screenId, layerId, layerMask), GRAPHIC_DISPLAY_SUCCESS);
197 GraphicLayerInfo layerInfo;
198 uint32_t cacheCount = 1;
199 ASSERT_EQ(HdiDeviceTest::hdiDevice_->CreateLayer(screenId, layerInfo, cacheCount, layerId),
200 GRAPHIC_DISPLAY_SUCCESS);
201 std::vector<std::string> valueRet = HdiDeviceTest::hdiDevice_->GetSupportedLayerPerFrameParameterKey();
202 const std::string validKey = "ArsrDoEnhance";
203 if (std::find(valueRet.begin(), valueRet.end(), validKey) != valueRet.end()) {
204 const std::vector<int8_t> valueBlob{static_cast<int8_t>(1)};
205 ASSERT_EQ(HdiDeviceTest::hdiDevice_->SetLayerPerFrameParameter(screenId, layerId, validKey, valueBlob),
206 GRAPHIC_DISPLAY_FAILURE);
207 }
208 ASSERT_EQ(HdiDeviceTest::hdiDevice_->CloseLayer(screenId, layerId), GRAPHIC_DISPLAY_SUCCESS);
209 }
210 } // namespace
211 } // namespace Rosen
212 } // namespace OHOS