• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 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 /* This files contains faultlog fuzzer test modules. */
17 
18 #define FUZZ_PROJECT_NAME "thermalservice_fuzzer"
19 #define private   public
20 #define protected public
21 
22 #include "thermal_fuzzer_test.h"
23 #include "ithermal_srv.h"
24 #include "thermal_service.h"
25 
26 using namespace OHOS::PowerMgr;
27 using namespace OHOS;
28 
29 namespace {
30 ThermalFuzzerTest g_serviceTest;
31 sptr<ThermalService> g_service = nullptr;
ThermalServiceFuzzTest001()32 void ThermalServiceFuzzTest001()
33 {
34     g_service = ThermalService::GetInstance();
35     g_service->InitSystemTestModules();
36     g_service->GetBaseinfoObj()->Init();
37     g_service->InitThermalObserver();
38     g_service->GetObserver()->InitSensorTypeMap();
39     g_service->OnStart();
40     std::string deviceId = "";
41     g_service->OnAddSystemAbility(COMMON_EVENT_SERVICE_ID, deviceId);
42     g_service->OnAddSystemAbility(SOC_PERF_SERVICE_SA_ID, deviceId);
43     g_service->OnAddSystemAbility(POWER_MANAGER_BATT_SERVICE_ID, deviceId);
44     g_service->RegisterBootCompletedCallback();
45     std::vector<std::string> typeList;
46     sptr<IThermalTempCallback> tempCallback = nullptr;
47     g_service->SubscribeThermalTempCallback(typeList, tempCallback);
48     g_service->UnSubscribeThermalTempCallback(tempCallback);
49     sptr<IThermalLevelCallback> levelCallback = nullptr;
50     g_service->SubscribeThermalLevelCallback(levelCallback);
51     g_service->UnSubscribeThermalLevelCallback(levelCallback);
52     std::vector<std::string> actionList;
53     actionList.push_back("cpu_big");
54     std::string desc = "";
55     sptr<IThermalActionCallback> actionCallback = nullptr;
56     g_service->SubscribeThermalActionCallback(actionList, desc, actionCallback);
57     g_service->UnSubscribeThermalActionCallback(actionCallback);
58     g_service->RegisterThermalHdiCallback();
59     g_service->UnRegisterThermalHdiCallback();
60     HdfThermalCallbackInfo event;
61     ThermalZoneInfo info;
62     info.type = "battery";
63     info.temp = 0;
64     event.info.push_back(info);
65     g_service->HandleThermalCallbackEvent(event);
66     TypeTempMap tempMap;
67     g_service->isTempReport_ = true;
68     g_service->HandleTempEmulation(tempMap);
69     g_service->RegisterFanHdiCallback();
70     g_service->HandleFanCallbackEvent(event);
71     int fd = 0;
72     std::vector<std::u16string> args;
73     args.push_back(u"-h");
74     g_service->Dump(fd, args);
75     g_service->isBootCompleted_ = true;
76     g_service->Dump(fd, args);
77     g_service->ready_ = true;
78     g_service->OnStop();
79     g_service->EnableMock("", nullptr);
80     g_service->DestroyInstance();
81 }
82 }
83 
84 /* Fuzzer entry point */
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)85 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
86 {
87     /* Run your code on data */
88     ThermalServiceFuzzTest001();
89     g_serviceTest.TestThermalServiceStub(static_cast<uint32_t>(IThermalSrvIpcCode::COMMAND_SHELL_DUMP), data, size);
90     return 0;
91 }
92