1 /*
2 * Copyright (c) 2023 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 #include "thermal_fuzzer_test.h"
19
20 #include <cstddef>
21 #include <cstdint>
22
23 #include "message_parcel.h"
24 #include "securec.h"
25
26 #include "thermal_policy.h"
27 #include "thermal_config_sensor_cluster.h"
28
29 using namespace OHOS::PowerMgr;
30 using namespace OHOS;
31
32 namespace {
33 const int32_t REWIND_READ_DATA = 0;
34 } // namespace
35
36 auto g_service = ThermalService::GetInstance();
37
ThermalFuzzerTest()38 ThermalFuzzerTest::ThermalFuzzerTest()
39 {
40 g_service->OnStart();
41 }
42
~ThermalFuzzerTest()43 ThermalFuzzerTest::~ThermalFuzzerTest()
44 {
45 if (g_service != nullptr) {
46 g_service->OnStop();
47 }
48 g_service = nullptr;
49 }
50
TestThermalPolicy()51 void ThermalFuzzerTest::TestThermalPolicy()
52 {
53 ThermalPolicy policy;
54 std::string result = "fuzz_test";
55 const TypeTempMap& info = {{"cpu", 30}, {"gpu", 45}};
56 policy.OnSensorInfoReported(info);
57 policy.DumpLevel(result);
58 policy.DumpPolicy(result);
59 }
60
TestThermalServiceStub(const uint32_t code,const uint8_t * data,size_t size)61 void ThermalFuzzerTest::TestThermalServiceStub(const uint32_t code, const uint8_t* data, size_t size)
62 {
63 MessageParcel datas;
64 datas.WriteInterfaceToken(ThermalService::GetDescriptor());
65 datas.WriteBuffer(data, size);
66 datas.RewindRead(REWIND_READ_DATA);
67 MessageParcel reply;
68 MessageOption option;
69 g_service->OnRemoteRequest(code, datas, reply, option);
70 }
71