1094332d3Sopenharmony_ci/* 2094332d3Sopenharmony_ci * Copyright (c) 2023 Huawei Device Co., Ltd. 3094332d3Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 4094332d3Sopenharmony_ci * you may not use this file except in compliance with the License. 5094332d3Sopenharmony_ci * You may obtain a copy of the License at 6094332d3Sopenharmony_ci * 7094332d3Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 8094332d3Sopenharmony_ci * 9094332d3Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 10094332d3Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 11094332d3Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12094332d3Sopenharmony_ci * See the License for the specific language governing permissions and 13094332d3Sopenharmony_ci * limitations under the License. 14094332d3Sopenharmony_ci */ 15094332d3Sopenharmony_ci 16094332d3Sopenharmony_ci#include "device_fuzzer.h" 17094332d3Sopenharmony_ci 18094332d3Sopenharmony_ci#include <cstddef> 19094332d3Sopenharmony_ci#include <cstdint> 20094332d3Sopenharmony_ci#include <securec.h> 21094332d3Sopenharmony_ci#include <string> 22094332d3Sopenharmony_ci 23094332d3Sopenharmony_ci#include "display_common_fuzzer.h" 24094332d3Sopenharmony_ci 25094332d3Sopenharmony_cinamespace OHOS { 26094332d3Sopenharmony_ciusing namespace OHOS::HDI::Display::Buffer::V1_0; 27094332d3Sopenharmony_ciusing namespace OHOS::HDI::Display::Composer::V1_2; 28094332d3Sopenharmony_ci 29094332d3Sopenharmony_cistatic sptr<Composer::V1_2::IDisplayComposerInterface> g_composerInterface = nullptr; 30094332d3Sopenharmony_cistatic std::shared_ptr<IDisplayBuffer> g_bufferInterface = nullptr; 31094332d3Sopenharmony_ci 32094332d3Sopenharmony_cistatic bool g_isInit = false; 33094332d3Sopenharmony_cistatic const uint8_t* g_data = nullptr; 34094332d3Sopenharmony_cistatic size_t g_dataSize = 0; 35094332d3Sopenharmony_cistatic size_t g_pos; 36094332d3Sopenharmony_ci 37094332d3Sopenharmony_ci/* 38094332d3Sopenharmony_ci* describe: get data from outside untrusted data(g_data) which size is according to sizeof(T) 39094332d3Sopenharmony_ci* tips: only support basic type 40094332d3Sopenharmony_ci*/ 41094332d3Sopenharmony_citemplate<class T> 42094332d3Sopenharmony_ciT GetData() 43094332d3Sopenharmony_ci{ 44094332d3Sopenharmony_ci T object {}; 45094332d3Sopenharmony_ci size_t objectSize = sizeof(object); 46094332d3Sopenharmony_ci if (g_data == nullptr || objectSize > g_dataSize - g_pos) { 47094332d3Sopenharmony_ci return object; 48094332d3Sopenharmony_ci } 49094332d3Sopenharmony_ci errno_t ret = memcpy_s(&object, objectSize, g_data + g_pos, objectSize); 50094332d3Sopenharmony_ci if (ret != EOK) { 51094332d3Sopenharmony_ci return {}; 52094332d3Sopenharmony_ci } 53094332d3Sopenharmony_ci g_pos += objectSize; 54094332d3Sopenharmony_ci return object; 55094332d3Sopenharmony_ci} 56094332d3Sopenharmony_ci 57094332d3Sopenharmony_cistatic int32_t GetAllocInfo(AllocInfo& info) 58094332d3Sopenharmony_ci{ 59094332d3Sopenharmony_ci uint32_t lenUsage = GetArrLength(CONVERT_TABLE_USAGE); 60094332d3Sopenharmony_ci if (lenUsage == 0) { 61094332d3Sopenharmony_ci HDF_LOGE("%{public}s: CONVERT_TABLE_USAGE length is equal to 0", __func__); 62094332d3Sopenharmony_ci return DISPLAY_FAILURE; 63094332d3Sopenharmony_ci } 64094332d3Sopenharmony_ci uint32_t lenFormat = GetArrLength(CONVERT_TABLE_FORMAT); 65094332d3Sopenharmony_ci if (lenFormat == 0) { 66094332d3Sopenharmony_ci HDF_LOGE("%{public}s: CONVERT_TABLE_FORMAT length is equal to 0", __func__); 67094332d3Sopenharmony_ci return DISPLAY_FAILURE; 68094332d3Sopenharmony_ci } 69094332d3Sopenharmony_ci 70094332d3Sopenharmony_ci info.width = GetData<uint32_t>() % WIDTH; 71094332d3Sopenharmony_ci info.height = GetData<uint32_t>() % HEIGHT; 72094332d3Sopenharmony_ci info.usage = CONVERT_TABLE_USAGE[GetData<uint32_t>() % lenUsage]; 73094332d3Sopenharmony_ci info.format = CONVERT_TABLE_FORMAT[GetData<uint32_t>() % lenFormat]; 74094332d3Sopenharmony_ci info.expectedSize = info.width * info.height; 75094332d3Sopenharmony_ci 76094332d3Sopenharmony_ci return DISPLAY_SUCCESS; 77094332d3Sopenharmony_ci} 78094332d3Sopenharmony_ci 79094332d3Sopenharmony_cistatic int32_t GetIRect(IRect& rect) 80094332d3Sopenharmony_ci{ 81094332d3Sopenharmony_ci rect.x = GetData<int32_t>(); 82094332d3Sopenharmony_ci rect.y = GetData<int32_t>(); 83094332d3Sopenharmony_ci rect.w = GetData<int32_t>(); 84094332d3Sopenharmony_ci rect.h = GetData<int32_t>(); 85094332d3Sopenharmony_ci return DISPLAY_SUCCESS; 86094332d3Sopenharmony_ci} 87094332d3Sopenharmony_ci 88094332d3Sopenharmony_ciBufferHandle* UsingAllocmem() 89094332d3Sopenharmony_ci{ 90094332d3Sopenharmony_ci AllocInfo info = { 0 }; 91094332d3Sopenharmony_ci int32_t ret = GetAllocInfo(info); 92094332d3Sopenharmony_ci if (ret != DISPLAY_SUCCESS) { 93094332d3Sopenharmony_ci HDF_LOGE("%{public}s: function GetAllocInfo failed", __func__); 94094332d3Sopenharmony_ci return nullptr; 95094332d3Sopenharmony_ci } 96094332d3Sopenharmony_ci 97094332d3Sopenharmony_ci BufferHandle* handle = nullptr; 98094332d3Sopenharmony_ci ret = g_bufferInterface->AllocMem(info, handle); 99094332d3Sopenharmony_ci if (ret != DISPLAY_SUCCESS) { 100094332d3Sopenharmony_ci HDF_LOGE("%{public}s: function AllocMem failed", __func__); 101094332d3Sopenharmony_ci return nullptr; 102094332d3Sopenharmony_ci } 103094332d3Sopenharmony_ci return handle; 104094332d3Sopenharmony_ci} 105094332d3Sopenharmony_ci 106094332d3Sopenharmony_ciint32_t TestSetClientBufferCacheCount(uint32_t devId) 107094332d3Sopenharmony_ci{ 108094332d3Sopenharmony_ci uint32_t cacheCount = GetData<uint32_t>(); 109094332d3Sopenharmony_ci int32_t ret = g_composerInterface->SetClientBufferCacheCount(devId, cacheCount); 110094332d3Sopenharmony_ci if (ret != DISPLAY_SUCCESS) { 111094332d3Sopenharmony_ci HDF_LOGE("%{public}s: function SetClientBufferCacheCount failed", __func__); 112094332d3Sopenharmony_ci return DISPLAY_FAILURE; 113094332d3Sopenharmony_ci } 114094332d3Sopenharmony_ci return ret; 115094332d3Sopenharmony_ci} 116094332d3Sopenharmony_ci 117094332d3Sopenharmony_ciint32_t TestGetDisplaySupportedModes(uint32_t devId) 118094332d3Sopenharmony_ci{ 119094332d3Sopenharmony_ci DisplayModeInfo info = { 0 }; 120094332d3Sopenharmony_ci info.width = GetData<int32_t>() % WIDTH; 121094332d3Sopenharmony_ci info.height = GetData<int32_t>() % HEIGHT; 122094332d3Sopenharmony_ci info.freshRate = GetData<uint32_t>(); 123094332d3Sopenharmony_ci info.id = GetData<int32_t>(); 124094332d3Sopenharmony_ci 125094332d3Sopenharmony_ci std::vector<DisplayModeInfo> infos; 126094332d3Sopenharmony_ci infos.push_back(info); 127094332d3Sopenharmony_ci int32_t ret = g_composerInterface->GetDisplaySupportedModes(devId, infos); 128094332d3Sopenharmony_ci if (ret != DISPLAY_SUCCESS) { 129094332d3Sopenharmony_ci HDF_LOGE("%{public}s: function GetDisplaySupportedModes failed", __func__); 130094332d3Sopenharmony_ci return DISPLAY_FAILURE; 131094332d3Sopenharmony_ci } 132094332d3Sopenharmony_ci return ret; 133094332d3Sopenharmony_ci} 134094332d3Sopenharmony_ci 135094332d3Sopenharmony_ciint32_t TestSetGetDisplayMode(uint32_t devId) 136094332d3Sopenharmony_ci{ 137094332d3Sopenharmony_ci uint32_t modeId = GetData<uint32_t>(); 138094332d3Sopenharmony_ci int32_t ret = g_composerInterface->SetDisplayMode(devId, modeId); 139094332d3Sopenharmony_ci if (ret != DISPLAY_SUCCESS) { 140094332d3Sopenharmony_ci HDF_LOGE("%{public}s: function SetDisplayMode failed", __func__); 141094332d3Sopenharmony_ci return DISPLAY_FAILURE; 142094332d3Sopenharmony_ci } 143094332d3Sopenharmony_ci ret = g_composerInterface->GetDisplayMode(devId, modeId); 144094332d3Sopenharmony_ci if (ret != DISPLAY_SUCCESS) { 145094332d3Sopenharmony_ci HDF_LOGE("%{public}s: function GetDisplayMode failed", __func__); 146094332d3Sopenharmony_ci return DISPLAY_FAILURE; 147094332d3Sopenharmony_ci } 148094332d3Sopenharmony_ci return ret; 149094332d3Sopenharmony_ci} 150094332d3Sopenharmony_ci 151094332d3Sopenharmony_ciint32_t TestSetGetDisplayPowerStatus(uint32_t devId) 152094332d3Sopenharmony_ci{ 153094332d3Sopenharmony_ci uint32_t len = GetArrLength(CONVERT_TABLE_POWER_STATUS); 154094332d3Sopenharmony_ci if (len == 0) { 155094332d3Sopenharmony_ci HDF_LOGE("%{public}s: CONVERT_TABLE_POWER_STATUS length is equal to 0", __func__); 156094332d3Sopenharmony_ci return DISPLAY_FAILURE; 157094332d3Sopenharmony_ci } 158094332d3Sopenharmony_ci Composer::V1_0::DispPowerStatus status = CONVERT_TABLE_POWER_STATUS[GetData<uint32_t>() % len]; 159094332d3Sopenharmony_ci int32_t ret = g_composerInterface->SetDisplayPowerStatus(devId, status); 160094332d3Sopenharmony_ci if (ret != DISPLAY_SUCCESS) { 161094332d3Sopenharmony_ci HDF_LOGE("%{public}s: function SetDisplayPowerStatus failed", __func__); 162094332d3Sopenharmony_ci return DISPLAY_FAILURE; 163094332d3Sopenharmony_ci } 164094332d3Sopenharmony_ci ret = g_composerInterface->GetDisplayPowerStatus(devId, status); 165094332d3Sopenharmony_ci if (ret != DISPLAY_SUCCESS) { 166094332d3Sopenharmony_ci HDF_LOGE("%{public}s: function GetDisplayPowerStatus failed", __func__); 167094332d3Sopenharmony_ci return DISPLAY_FAILURE; 168094332d3Sopenharmony_ci } 169094332d3Sopenharmony_ci return ret; 170094332d3Sopenharmony_ci} 171094332d3Sopenharmony_ci 172094332d3Sopenharmony_ciint32_t TestPrepareDisplayLayers(uint32_t devId) 173094332d3Sopenharmony_ci{ 174094332d3Sopenharmony_ci bool needFlushFb = GetRandBoolValue(GetData<uint32_t>()); 175094332d3Sopenharmony_ci int32_t ret = g_composerInterface->PrepareDisplayLayers(devId, needFlushFb); 176094332d3Sopenharmony_ci if (ret != DISPLAY_SUCCESS) { 177094332d3Sopenharmony_ci HDF_LOGE("%{public}s: function PrepareDisplayLayers failed", __func__); 178094332d3Sopenharmony_ci return DISPLAY_FAILURE; 179094332d3Sopenharmony_ci } 180094332d3Sopenharmony_ci return ret; 181094332d3Sopenharmony_ci} 182094332d3Sopenharmony_ci 183094332d3Sopenharmony_ciint32_t TestSetGetDisplayBacklight(uint32_t devId) 184094332d3Sopenharmony_ci{ 185094332d3Sopenharmony_ci uint32_t level = GetData<uint32_t>(); 186094332d3Sopenharmony_ci int32_t ret = g_composerInterface->SetDisplayBacklight(devId, level); 187094332d3Sopenharmony_ci if (ret != DISPLAY_SUCCESS) { 188094332d3Sopenharmony_ci HDF_LOGE("%{public}s: function SetDisplayBacklight failed", __func__); 189094332d3Sopenharmony_ci return DISPLAY_FAILURE; 190094332d3Sopenharmony_ci } 191094332d3Sopenharmony_ci ret = g_composerInterface->GetDisplayBacklight(devId, level); 192094332d3Sopenharmony_ci if (ret != DISPLAY_SUCCESS) { 193094332d3Sopenharmony_ci HDF_LOGE("%{public}s: function GetDisplayBacklight failed", __func__); 194094332d3Sopenharmony_ci return DISPLAY_FAILURE; 195094332d3Sopenharmony_ci } 196094332d3Sopenharmony_ci return ret; 197094332d3Sopenharmony_ci} 198094332d3Sopenharmony_ci 199094332d3Sopenharmony_ciint32_t TestGetDisplayProperty(uint32_t devId) 200094332d3Sopenharmony_ci{ 201094332d3Sopenharmony_ci uint32_t id = GetData<uint32_t>(); 202094332d3Sopenharmony_ci uint64_t value = GetData<uint32_t>(); 203094332d3Sopenharmony_ci int32_t ret = g_composerInterface->GetDisplayProperty(devId, id, value); 204094332d3Sopenharmony_ci if (ret != DISPLAY_SUCCESS) { 205094332d3Sopenharmony_ci HDF_LOGE("%{public}s: function GetDisplayProperty failed", __func__); 206094332d3Sopenharmony_ci return DISPLAY_FAILURE; 207094332d3Sopenharmony_ci } 208094332d3Sopenharmony_ci return ret; 209094332d3Sopenharmony_ci} 210094332d3Sopenharmony_ci 211094332d3Sopenharmony_ciint32_t TestSetHardwareCursorPosition(uint32_t devId) 212094332d3Sopenharmony_ci{ 213094332d3Sopenharmony_ci int32_t x = GetData<uint32_t>(); 214094332d3Sopenharmony_ci int32_t y = GetData<uint32_t>(); 215094332d3Sopenharmony_ci int32_t ret = g_composerInterface->SetHardwareCursorPosition(devId, x, y); 216094332d3Sopenharmony_ci if ((ret != DISPLAY_SUCCESS) && (ret != DISPLAY_NOT_SUPPORT)) { 217094332d3Sopenharmony_ci HDF_LOGE("%{public}s: function SetHardwareCursorPosition failed, %{public}d", __func__, ret); 218094332d3Sopenharmony_ci return DISPLAY_FAILURE; 219094332d3Sopenharmony_ci } 220094332d3Sopenharmony_ci return DISPLAY_SUCCESS; 221094332d3Sopenharmony_ci} 222094332d3Sopenharmony_ci 223094332d3Sopenharmony_ciint32_t TestEnableHardwareCursorStats(uint32_t devId) 224094332d3Sopenharmony_ci{ 225094332d3Sopenharmony_ci bool enable = GetRandBoolValue(GetData<uint32_t>()); 226094332d3Sopenharmony_ci int32_t ret = g_composerInterface->EnableHardwareCursorStats(devId, enable); 227094332d3Sopenharmony_ci if ((ret != DISPLAY_SUCCESS) && (ret != DISPLAY_NOT_SUPPORT)) { 228094332d3Sopenharmony_ci HDF_LOGE("%{public}s: function EnableHardwareCursorStats failed, %{public}d", __func__, ret); 229094332d3Sopenharmony_ci return DISPLAY_FAILURE; 230094332d3Sopenharmony_ci } 231094332d3Sopenharmony_ci return DISPLAY_SUCCESS; 232094332d3Sopenharmony_ci} 233094332d3Sopenharmony_ci 234094332d3Sopenharmony_ciint32_t TestGetHardwareCursorStats(uint32_t devId) 235094332d3Sopenharmony_ci{ 236094332d3Sopenharmony_ci uint32_t frameCount = GetData<uint32_t>(); 237094332d3Sopenharmony_ci uint32_t vsyncCount = GetData<uint32_t>(); 238094332d3Sopenharmony_ci int32_t ret = g_composerInterface->GetHardwareCursorStats(devId, frameCount, vsyncCount); 239094332d3Sopenharmony_ci if ((ret != DISPLAY_SUCCESS) && (ret != DISPLAY_NOT_SUPPORT)) { 240094332d3Sopenharmony_ci HDF_LOGE("%{public}s: function GetHardwareCursorStats failed, %{public}d", __func__, ret); 241094332d3Sopenharmony_ci return DISPLAY_FAILURE; 242094332d3Sopenharmony_ci } 243094332d3Sopenharmony_ci return DISPLAY_SUCCESS; 244094332d3Sopenharmony_ci} 245094332d3Sopenharmony_ci 246094332d3Sopenharmony_ciint32_t TestGetDisplayCompChange(uint32_t devId) 247094332d3Sopenharmony_ci{ 248094332d3Sopenharmony_ci std::vector<uint32_t> layers; 249094332d3Sopenharmony_ci layers.push_back(GetData<uint32_t>()); 250094332d3Sopenharmony_ci std::vector<int32_t> types; 251094332d3Sopenharmony_ci types.push_back(GetData<int32_t>()); 252094332d3Sopenharmony_ci 253094332d3Sopenharmony_ci int32_t ret = g_composerInterface->GetDisplayCompChange(devId, layers, types); 254094332d3Sopenharmony_ci if (ret != DISPLAY_SUCCESS) { 255094332d3Sopenharmony_ci HDF_LOGE("%{public}s: function GetDisplayCompChange failed", __func__); 256094332d3Sopenharmony_ci return DISPLAY_FAILURE; 257094332d3Sopenharmony_ci } 258094332d3Sopenharmony_ci return ret; 259094332d3Sopenharmony_ci} 260094332d3Sopenharmony_ci 261094332d3Sopenharmony_ciint32_t TestSetDisplayClientCrop(uint32_t devId) 262094332d3Sopenharmony_ci{ 263094332d3Sopenharmony_ci IRect rect; 264094332d3Sopenharmony_ci int32_t ret = GetIRect(rect); 265094332d3Sopenharmony_ci if (ret != DISPLAY_SUCCESS) { 266094332d3Sopenharmony_ci HDF_LOGE("%{public}s: function GetIRect failed", __func__); 267094332d3Sopenharmony_ci return DISPLAY_FAILURE; 268094332d3Sopenharmony_ci } 269094332d3Sopenharmony_ci ret = g_composerInterface->SetDisplayClientCrop(devId, rect); 270094332d3Sopenharmony_ci if (ret != DISPLAY_SUCCESS) { 271094332d3Sopenharmony_ci HDF_LOGE("%{public}s: function SetDisplayClientCrop failed", __func__); 272094332d3Sopenharmony_ci return DISPLAY_FAILURE; 273094332d3Sopenharmony_ci } 274094332d3Sopenharmony_ci return ret; 275094332d3Sopenharmony_ci} 276094332d3Sopenharmony_ci 277094332d3Sopenharmony_ciint32_t TestSetDisplayClientDamage(uint32_t devId) 278094332d3Sopenharmony_ci{ 279094332d3Sopenharmony_ci IRect rect; 280094332d3Sopenharmony_ci int32_t ret = GetIRect(rect); 281094332d3Sopenharmony_ci if (ret != DISPLAY_SUCCESS) { 282094332d3Sopenharmony_ci HDF_LOGE("%{public}s: function GetIRect failed", __func__); 283094332d3Sopenharmony_ci return DISPLAY_FAILURE; 284094332d3Sopenharmony_ci } 285094332d3Sopenharmony_ci std::vector<IRect> rects; 286094332d3Sopenharmony_ci rects.push_back(rect); 287094332d3Sopenharmony_ci ret = g_composerInterface->SetDisplayClientDamage(devId, rects); 288094332d3Sopenharmony_ci if (ret != DISPLAY_SUCCESS) { 289094332d3Sopenharmony_ci HDF_LOGE("%{public}s: function SetDisplayClientDamage failed", __func__); 290094332d3Sopenharmony_ci } 291094332d3Sopenharmony_ci return ret; 292094332d3Sopenharmony_ci} 293094332d3Sopenharmony_ci 294094332d3Sopenharmony_ciint32_t TestSetDisplayVsyncEnabled(uint32_t devId) 295094332d3Sopenharmony_ci{ 296094332d3Sopenharmony_ci bool enabled = GetRandBoolValue(GetData<uint32_t>()); 297094332d3Sopenharmony_ci int32_t ret = g_composerInterface->SetDisplayVsyncEnabled(devId, enabled); 298094332d3Sopenharmony_ci if (ret != DISPLAY_SUCCESS) { 299094332d3Sopenharmony_ci HDF_LOGE("%{public}s: function SetDisplayVsyncEnabled failed", __func__); 300094332d3Sopenharmony_ci } 301094332d3Sopenharmony_ci return ret; 302094332d3Sopenharmony_ci} 303094332d3Sopenharmony_ci 304094332d3Sopenharmony_ciint32_t TestRegDisplayVBlankCallback(uint32_t devId) 305094332d3Sopenharmony_ci{ 306094332d3Sopenharmony_ci uint32_t param1 = GetData<uint32_t>(); 307094332d3Sopenharmony_ci VBlankCallback param2 = GetData<VBlankCallback>(); 308094332d3Sopenharmony_ci void* param3 = malloc(PARAM_VOIDPTR_LEN); 309094332d3Sopenharmony_ci if (param3 == nullptr) { 310094332d3Sopenharmony_ci HDF_LOGE("%{public}s: void* param3 malloc failed", __func__); 311094332d3Sopenharmony_ci return DISPLAY_FAILURE; 312094332d3Sopenharmony_ci } 313094332d3Sopenharmony_ci int32_t ret = g_composerInterface->RegDisplayVBlankCallback(param1, param2, param3); 314094332d3Sopenharmony_ci if (ret != DISPLAY_SUCCESS) { 315094332d3Sopenharmony_ci HDF_LOGE("%{public}s: function RegDisplayVBlankCallback failed", __func__); 316094332d3Sopenharmony_ci } 317094332d3Sopenharmony_ci free(param3); 318094332d3Sopenharmony_ci param3 = nullptr; 319094332d3Sopenharmony_ci return ret; 320094332d3Sopenharmony_ci} 321094332d3Sopenharmony_ci 322094332d3Sopenharmony_ciint32_t TestGetDisplayReleaseFence(uint32_t devId) 323094332d3Sopenharmony_ci{ 324094332d3Sopenharmony_ci std::vector<uint32_t> layers; 325094332d3Sopenharmony_ci layers.push_back(GetData<uint32_t>()); 326094332d3Sopenharmony_ci std::vector<int32_t> fences; 327094332d3Sopenharmony_ci fences.push_back(GetData<int32_t>()); 328094332d3Sopenharmony_ci 329094332d3Sopenharmony_ci int32_t ret = g_composerInterface->GetDisplayReleaseFence(devId, layers, fences); 330094332d3Sopenharmony_ci if (ret != DISPLAY_SUCCESS) { 331094332d3Sopenharmony_ci HDF_LOGE("%{public}s: function GetDisplayReleaseFence failed", __func__); 332094332d3Sopenharmony_ci } 333094332d3Sopenharmony_ci return ret; 334094332d3Sopenharmony_ci} 335094332d3Sopenharmony_ci 336094332d3Sopenharmony_ciint32_t TestDestroyVirtualDisplay(uint32_t devId) 337094332d3Sopenharmony_ci{ 338094332d3Sopenharmony_ci int32_t ret = g_composerInterface->DestroyVirtualDisplay(devId); 339094332d3Sopenharmony_ci if (ret != DISPLAY_SUCCESS) { 340094332d3Sopenharmony_ci HDF_LOGE("%{public}s: function DestroyVirtualDisplay failed", __func__); 341094332d3Sopenharmony_ci } 342094332d3Sopenharmony_ci return ret; 343094332d3Sopenharmony_ci} 344094332d3Sopenharmony_ci 345094332d3Sopenharmony_ciint32_t TestSetVirtualDisplayBuffer(uint32_t devId) 346094332d3Sopenharmony_ci{ 347094332d3Sopenharmony_ci int32_t fence = GetData<int32_t>(); 348094332d3Sopenharmony_ci BufferHandle* buffer = UsingAllocmem(); 349094332d3Sopenharmony_ci if (buffer == nullptr) { 350094332d3Sopenharmony_ci HDF_LOGE("%{public}s: Failed to UsingAllocmem", __func__); 351094332d3Sopenharmony_ci return DISPLAY_FAILURE; 352094332d3Sopenharmony_ci } 353094332d3Sopenharmony_ci int32_t ret = g_composerInterface->SetVirtualDisplayBuffer(devId, *buffer, fence); 354094332d3Sopenharmony_ci if (ret != DISPLAY_SUCCESS) { 355094332d3Sopenharmony_ci HDF_LOGE("%{public}s: function SetVirtualDisplayBuffer failed", __func__); 356094332d3Sopenharmony_ci } 357094332d3Sopenharmony_ci g_bufferInterface->FreeMem(*buffer); 358094332d3Sopenharmony_ci return ret; 359094332d3Sopenharmony_ci} 360094332d3Sopenharmony_ci 361094332d3Sopenharmony_ciint32_t TestSetDisplayProperty(uint32_t devId) 362094332d3Sopenharmony_ci{ 363094332d3Sopenharmony_ci uint32_t id = GetData<uint32_t>(); 364094332d3Sopenharmony_ci uint64_t value = GetData<uint64_t>(); 365094332d3Sopenharmony_ci int32_t ret = g_composerInterface->SetDisplayProperty(devId, id, value); 366094332d3Sopenharmony_ci if (ret != DISPLAY_SUCCESS) { 367094332d3Sopenharmony_ci HDF_LOGE("%{public}s: SetDisplayProperty failed", __func__); 368094332d3Sopenharmony_ci } 369094332d3Sopenharmony_ci return ret; 370094332d3Sopenharmony_ci} 371094332d3Sopenharmony_ci 372094332d3Sopenharmony_ciint32_t TestCommit(uint32_t devId) 373094332d3Sopenharmony_ci{ 374094332d3Sopenharmony_ci int32_t fence = GetData<int32_t>(); 375094332d3Sopenharmony_ci int32_t ret = g_composerInterface->Commit(devId, fence); 376094332d3Sopenharmony_ci if (ret != DISPLAY_SUCCESS) { 377094332d3Sopenharmony_ci HDF_LOGE("%{public}s: function Commit failed", __func__); 378094332d3Sopenharmony_ci } 379094332d3Sopenharmony_ci return ret; 380094332d3Sopenharmony_ci} 381094332d3Sopenharmony_ci 382094332d3Sopenharmony_ciint TestGetDisplaySupportedModesExt(uint32_t devId) 383094332d3Sopenharmony_ci{ 384094332d3Sopenharmony_ci std::vector<DisplayModeInfoExt> modes; 385094332d3Sopenharmony_ci modes.push_back(GetData<DisplayModeInfoExt>()); 386094332d3Sopenharmony_ci int32_t ret = g_composerInterface->GetDisplaySupportedModesExt(devId, modes); 387094332d3Sopenharmony_ci if ((ret != DISPLAY_SUCCESS) && (ret != DISPLAY_NOT_SUPPORT)) { 388094332d3Sopenharmony_ci HDF_LOGE("%{public}s: GetDisplaySupportedModesExt failed", __func__); 389094332d3Sopenharmony_ci } 390094332d3Sopenharmony_ci return ret; 391094332d3Sopenharmony_ci} 392094332d3Sopenharmony_ci 393094332d3Sopenharmony_civoid TestModeCallback(uint32_t modeId, uint64_t vBlankPeriod, void* data) 394094332d3Sopenharmony_ci{ 395094332d3Sopenharmony_ci} 396094332d3Sopenharmony_ci 397094332d3Sopenharmony_ciint TestSetDisplayModeAsync(uint32_t devId) 398094332d3Sopenharmony_ci{ 399094332d3Sopenharmony_ci uint32_t modeid = GetData<uint32_t>(); 400094332d3Sopenharmony_ci int32_t ret = g_composerInterface->SetDisplayModeAsync(devId, modeid, TestModeCallback); 401094332d3Sopenharmony_ci if ((ret != DISPLAY_SUCCESS) && (ret != DISPLAY_NOT_SUPPORT)) { 402094332d3Sopenharmony_ci HDF_LOGE("%{public}s: SetDisplayModeAsync failed", __func__); 403094332d3Sopenharmony_ci } 404094332d3Sopenharmony_ci return ret; 405094332d3Sopenharmony_ci} 406094332d3Sopenharmony_ci 407094332d3Sopenharmony_ciint TestGetDisplayVBlankPeriod(uint32_t devId) 408094332d3Sopenharmony_ci{ 409094332d3Sopenharmony_ci uint64_t period = GetData<uint64_t>(); 410094332d3Sopenharmony_ci int32_t ret = g_composerInterface->GetDisplayVBlankPeriod(devId, period); 411094332d3Sopenharmony_ci if ((ret != DISPLAY_SUCCESS) && (ret != DISPLAY_NOT_SUPPORT)) { 412094332d3Sopenharmony_ci HDF_LOGE("%{public}s: GetDisplayVBlankPeriod failed", __func__); 413094332d3Sopenharmony_ci } 414094332d3Sopenharmony_ci return ret; 415094332d3Sopenharmony_ci} 416094332d3Sopenharmony_ci 417094332d3Sopenharmony_civoid TestSeamlessChangeCallback(uint32_t devId, void* data) 418094332d3Sopenharmony_ci{ 419094332d3Sopenharmony_ci} 420094332d3Sopenharmony_ci 421094332d3Sopenharmony_ciint TestRegSeamlessChangeCallback(uint32_t devId) 422094332d3Sopenharmony_ci{ 423094332d3Sopenharmony_ci int32_t ret = g_composerInterface->RegSeamlessChangeCallback(TestSeamlessChangeCallback, nullptr); 424094332d3Sopenharmony_ci if ((ret != DISPLAY_SUCCESS) && (ret != DISPLAY_NOT_SUPPORT)) { 425094332d3Sopenharmony_ci HDF_LOGE("%{public}s: SetDisplayModeAsync failed", __func__); 426094332d3Sopenharmony_ci } 427094332d3Sopenharmony_ci return ret; 428094332d3Sopenharmony_ci} 429094332d3Sopenharmony_ci 430094332d3Sopenharmony_ciint TestGetSupportedLayerPerFrameParameterKey(uint32_t devId) 431094332d3Sopenharmony_ci{ 432094332d3Sopenharmony_ci std::vector<std::string> keys; 433094332d3Sopenharmony_ci int32_t ret = g_composerInterface->GetSupportedLayerPerFrameParameterKey(keys); 434094332d3Sopenharmony_ci if ((ret != DISPLAY_SUCCESS) && (ret != DISPLAY_NOT_SUPPORT)) { 435094332d3Sopenharmony_ci HDF_LOGE("%{public}s: failed with ret=%{public}d", __func__, ret); 436094332d3Sopenharmony_ci } 437094332d3Sopenharmony_ci return ret; 438094332d3Sopenharmony_ci} 439094332d3Sopenharmony_ci 440094332d3Sopenharmony_ciint TestSetDisplayOverlayResolution(uint32_t devId) 441094332d3Sopenharmony_ci{ 442094332d3Sopenharmony_ci uint32_t width = GetData<uint32_t>() % WIDTH; 443094332d3Sopenharmony_ci uint32_t height = GetData<uint32_t>() % HEIGHT; 444094332d3Sopenharmony_ci int32_t ret = g_composerInterface->SetDisplayOverlayResolution(devId, width, height); 445094332d3Sopenharmony_ci if ((ret != DISPLAY_SUCCESS) && (ret != DISPLAY_NOT_SUPPORT)) { 446094332d3Sopenharmony_ci HDF_LOGE("%{public}s: failed with ret=%{public}d", __func__, ret); 447094332d3Sopenharmony_ci } 448094332d3Sopenharmony_ci return ret; 449094332d3Sopenharmony_ci} 450094332d3Sopenharmony_ci 451094332d3Sopenharmony_cistatic void TestRefreshCallback(uint32_t devId, void* data) 452094332d3Sopenharmony_ci{ 453094332d3Sopenharmony_ci} 454094332d3Sopenharmony_ci 455094332d3Sopenharmony_ciint TestRegRefreshCallback(uint32_t devId) 456094332d3Sopenharmony_ci{ 457094332d3Sopenharmony_ci int32_t ret = g_composerInterface->RegRefreshCallback(TestRefreshCallback, nullptr); 458094332d3Sopenharmony_ci if ((ret != DISPLAY_SUCCESS) && (ret != DISPLAY_NOT_SUPPORT)) { 459094332d3Sopenharmony_ci HDF_LOGE("%{public}s: failed with ret=%{public}d", __func__, ret); 460094332d3Sopenharmony_ci } 461094332d3Sopenharmony_ci return ret; 462094332d3Sopenharmony_ci} 463094332d3Sopenharmony_ci 464094332d3Sopenharmony_ciint TestGetDisplaySupportedColorGamuts(uint32_t devId) 465094332d3Sopenharmony_ci{ 466094332d3Sopenharmony_ci std::vector<ColorGamut> gamuts; 467094332d3Sopenharmony_ci int32_t ret = g_composerInterface->GetDisplaySupportedColorGamuts(devId, gamuts); 468094332d3Sopenharmony_ci if ((ret != DISPLAY_SUCCESS) && (ret != DISPLAY_NOT_SUPPORT)) { 469094332d3Sopenharmony_ci HDF_LOGE("%{public}s: failed with ret=%{public}d", __func__, ret); 470094332d3Sopenharmony_ci } 471094332d3Sopenharmony_ci return ret; 472094332d3Sopenharmony_ci} 473094332d3Sopenharmony_ci 474094332d3Sopenharmony_ciint TestGetHDRCapabilityInfos(uint32_t devId) 475094332d3Sopenharmony_ci{ 476094332d3Sopenharmony_ci HDRCapability info = { 0 }; 477094332d3Sopenharmony_ci int32_t ret = g_composerInterface->GetHDRCapabilityInfos(devId, info); 478094332d3Sopenharmony_ci if ((ret != DISPLAY_SUCCESS) && (ret != DISPLAY_NOT_SUPPORT)) { 479094332d3Sopenharmony_ci HDF_LOGE("%{public}s: failed with ret=%{public}d", __func__, ret); 480094332d3Sopenharmony_ci } 481094332d3Sopenharmony_ci return ret; 482094332d3Sopenharmony_ci} 483094332d3Sopenharmony_ci 484094332d3Sopenharmony_citypedef int32_t (*TestFuncs[])(uint32_t); 485094332d3Sopenharmony_ci 486094332d3Sopenharmony_ciTestFuncs g_testFuncs = { 487094332d3Sopenharmony_ci TestSetClientBufferCacheCount, 488094332d3Sopenharmony_ci TestGetDisplaySupportedModes, 489094332d3Sopenharmony_ci TestSetGetDisplayMode, 490094332d3Sopenharmony_ci TestSetGetDisplayPowerStatus, 491094332d3Sopenharmony_ci TestPrepareDisplayLayers, 492094332d3Sopenharmony_ci TestSetGetDisplayBacklight, 493094332d3Sopenharmony_ci TestGetDisplayProperty, 494094332d3Sopenharmony_ci TestSetHardwareCursorPosition, 495094332d3Sopenharmony_ci TestEnableHardwareCursorStats, 496094332d3Sopenharmony_ci TestGetHardwareCursorStats, 497094332d3Sopenharmony_ci TestGetDisplayCompChange, 498094332d3Sopenharmony_ci TestSetDisplayClientCrop, 499094332d3Sopenharmony_ci TestSetDisplayClientDamage, 500094332d3Sopenharmony_ci TestSetDisplayVsyncEnabled, 501094332d3Sopenharmony_ci TestGetDisplayReleaseFence, 502094332d3Sopenharmony_ci TestDestroyVirtualDisplay, 503094332d3Sopenharmony_ci TestSetVirtualDisplayBuffer, 504094332d3Sopenharmony_ci TestSetDisplayProperty, 505094332d3Sopenharmony_ci TestGetDisplaySupportedModesExt, 506094332d3Sopenharmony_ci TestSetDisplayModeAsync, 507094332d3Sopenharmony_ci TestGetDisplayVBlankPeriod, 508094332d3Sopenharmony_ci TestRegSeamlessChangeCallback, 509094332d3Sopenharmony_ci TestGetSupportedLayerPerFrameParameterKey, 510094332d3Sopenharmony_ci TestSetDisplayOverlayResolution, 511094332d3Sopenharmony_ci TestRegRefreshCallback, 512094332d3Sopenharmony_ci TestGetDisplaySupportedColorGamuts, 513094332d3Sopenharmony_ci TestGetHDRCapabilityInfos, 514094332d3Sopenharmony_ci TestCommit, 515094332d3Sopenharmony_ci}; 516094332d3Sopenharmony_ci 517094332d3Sopenharmony_cibool FuzzTest(const uint8_t* rawData, size_t size) 518094332d3Sopenharmony_ci{ 519094332d3Sopenharmony_ci if (rawData == nullptr) { 520094332d3Sopenharmony_ci return false; 521094332d3Sopenharmony_ci } 522094332d3Sopenharmony_ci 523094332d3Sopenharmony_ci // initialize service 524094332d3Sopenharmony_ci if (!g_isInit) { 525094332d3Sopenharmony_ci g_isInit = true; 526094332d3Sopenharmony_ci g_composerInterface = Composer::V1_2::IDisplayComposerInterface::Get(); 527094332d3Sopenharmony_ci if (g_composerInterface == nullptr) { 528094332d3Sopenharmony_ci HDF_LOGE("%{public}s: get IDisplayComposerInterface failed", __func__); 529094332d3Sopenharmony_ci return false; 530094332d3Sopenharmony_ci } 531094332d3Sopenharmony_ci g_bufferInterface.reset(IDisplayBuffer::Get()); 532094332d3Sopenharmony_ci if (g_bufferInterface == nullptr) { 533094332d3Sopenharmony_ci HDF_LOGE("%{public}s: get IDisplayBuffer failed", __func__); 534094332d3Sopenharmony_ci return false; 535094332d3Sopenharmony_ci } 536094332d3Sopenharmony_ci } 537094332d3Sopenharmony_ci 538094332d3Sopenharmony_ci // initialize data 539094332d3Sopenharmony_ci g_data = rawData; 540094332d3Sopenharmony_ci g_dataSize = size; 541094332d3Sopenharmony_ci g_pos = 0; 542094332d3Sopenharmony_ci 543094332d3Sopenharmony_ci uint32_t code = GetData<uint32_t>(); 544094332d3Sopenharmony_ci uint32_t devId = GetData<uint32_t>(); 545094332d3Sopenharmony_ci uint32_t len = GetArrLength(g_testFuncs); 546094332d3Sopenharmony_ci if (len == 0) { 547094332d3Sopenharmony_ci HDF_LOGE("%{public}s: g_testFuncs length is equal to 0", __func__); 548094332d3Sopenharmony_ci return false; 549094332d3Sopenharmony_ci } 550094332d3Sopenharmony_ci 551094332d3Sopenharmony_ci int32_t ret = g_testFuncs[code % len](devId); 552094332d3Sopenharmony_ci if (ret != DISPLAY_SUCCESS) { 553094332d3Sopenharmony_ci HDF_LOGE("function %{public}u failed", code % len); 554094332d3Sopenharmony_ci return false; 555094332d3Sopenharmony_ci } 556094332d3Sopenharmony_ci 557094332d3Sopenharmony_ci return true; 558094332d3Sopenharmony_ci} 559094332d3Sopenharmony_ci} // OHOS 560094332d3Sopenharmony_ci 561094332d3Sopenharmony_ci/* Fuzzer entry point */ 562094332d3Sopenharmony_ciextern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) 563094332d3Sopenharmony_ci{ 564094332d3Sopenharmony_ci if (size < OHOS::THRESHOLD) { 565094332d3Sopenharmony_ci return 0; 566094332d3Sopenharmony_ci } 567094332d3Sopenharmony_ci 568094332d3Sopenharmony_ci OHOS::FuzzTest(data, size); 569094332d3Sopenharmony_ci return 0; 570094332d3Sopenharmony_ci} 571