1 /*
2 * Copyright (c) 2024 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 "vsyncadapter_fuzzer.h"
17
18 #include <cstring>
19 #include <fuzzer/FuzzedDataProvider.h>
20
21 #define private public
22 #include "vsync_adapter_impl.h"
23 #undef private
24
25 using namespace OHOS::NWeb;
26
27 namespace OHOS {
OnVsyncCallback()28 static void OnVsyncCallback() {}
29 constexpr int MAX_SET_NUMBER = 1000;
30
CameraManagerAdapterFuzzTest(const uint8_t * data,size_t size)31 bool CameraManagerAdapterFuzzTest(const uint8_t* data, size_t size)
32 {
33 VSyncAdapterImpl& adapter = VSyncAdapterImpl::GetInstance();
34 adapter.Init();
35 adapter.Init();
36
37 VSyncAdapterImpl vsyncAdapter;
38 void* client = nullptr;
39 FuzzedDataProvider dataProvider(data, size);
40 int64_t timestamp = dataProvider.ConsumeIntegralInRange<int64_t>(0, MAX_SET_NUMBER);
41 adapter.OnVsync(timestamp, client);
42 client = &vsyncAdapter;
43 adapter.OnVsync(timestamp, client);
44 adapter.VsyncCallbackInner(1);
45 adapter.GetVSyncPeriod();
46 adapter.SetFrameRateLinkerEnable(true);
47 adapter.SetFramePreferredRate(0);
48 adapter.frameRateLinker_ = nullptr;
49 adapter.SetFrameRateLinkerEnable(true);
50 adapter.SetFramePreferredRate(0);
51 adapter.vsyncHandler_ = nullptr;
52 adapter.SetOnVsyncCallback(OnVsyncCallback);
53 adapter.SetOnVsyncEndCallback(OnVsyncCallback);
54 adapter.OnVsync(1, client);
55 adapter.SetIsGPUProcess(false);
56
57 return true;
58 }
59 } // namespace OHOS
60
61 /* Fuzzer entry point */
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)62 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
63 {
64 /* Run your code on data */
65 OHOS::CameraManagerAdapterFuzzTest(data, size);
66 return 0;
67 }
68