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 #define private public
17
18 #include <fuzzer/FuzzedDataProvider.h>
19
20 #include "aging_request.h"
21 #include "bms_fuzztest_util.h"
22 #include "bmsagingrequest_fuzzer.h"
23 #include "securec.h"
24
25 using namespace OHOS::AppExecFwk;
26 using namespace OHOS::AppExecFwk::BMSFuzzTestUtil;
27 namespace OHOS {
DoSomethingInterestingWithMyAPI(const uint8_t * data,size_t size)28 bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size)
29 {
30 FuzzedDataProvider fdp(data, size);
31 AgingBundleInfo bundleInfo;
32 AgingRequest agingRequest;
33 agingRequest.IsReachStartAgingThreshold();
34 agingRequest.IsReachEndAgingThreshold();
35 agingRequest.SortAgingBundles();
36 agingRequest.ResetRequest();
37 agingRequest.Dump();
38 agingRequest.AddAgingBundle(bundleInfo);
39 agingRequest.GetAgingBundles();
40 int64_t dataBytes = fdp.ConsumeIntegral<int64_t>();
41 agingRequest.UpdateTotalDataBytesAfterUninstalled(dataBytes);
42 agingRequest.GetTotalDataBytes();
43 agingRequest.SetTotalDataBytes(dataBytes);
44 AgingCleanType agingCleanType = static_cast<AgingCleanType>(fdp.ConsumeIntegral<uint8_t>() % CODE_MAX_TWO);
45 agingRequest.SetAgingCleanType(agingCleanType);
46 agingRequest.GetAgingCleanType();
47 agingRequest.GetTotalDataBytesThreshold();
48 agingRequest.GetOneDayTimeMs();
49 agingRequest.InitAgingPolicySystemParameters();
50 agingRequest.InitAgingDatasizeThreshold();
51 agingRequest.InitAgingOneDayTimeMs();
52 return true;
53 }
54 } // namespace OHOS
55
56 // Fuzzer entry point.
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)57 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
58 {
59 /* Run your code on data */
60 OHOS::DoSomethingInterestingWithMyAPI(data, size);
61 return 0;
62 }
63