1 /*
2 * Copyright (c) 2022 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 "audioresumecapture_fuzzer.h"
17 #include "audio_hdi_fuzzer_common.h"
18
19 using namespace OHOS::Audio;
20 namespace OHOS {
21 namespace Audio {
AudioResumeCaptureFuzzTest(const uint8_t * data,size_t size)22 bool AudioResumeCaptureFuzzTest(const uint8_t *data, size_t size)
23 {
24 bool result = false;
25 TestAudioManager *resumeFuzzManager = nullptr;
26 struct AudioAdapter *resumeFuzzAdapter = nullptr;
27 struct AudioCapture *resumeFuzzCapture = nullptr;
28 int32_t ret = AudioGetManagerCreateStartCapture(resumeFuzzManager, &resumeFuzzAdapter, &resumeFuzzCapture);
29 if (ret < 0 || resumeFuzzAdapter == nullptr || resumeFuzzCapture == nullptr || resumeFuzzManager == nullptr) {
30 HDF_LOGE("%{public}s: AudioGetManagerCreateStartCapture failed \n", __func__);
31 return false;
32 }
33 ret = resumeFuzzCapture->control.Pause((AudioHandle)resumeFuzzCapture);
34 if (ret < 0) {
35 resumeFuzzAdapter->DestroyCapture(resumeFuzzAdapter, resumeFuzzCapture);
36 resumeFuzzManager->UnloadAdapter(resumeFuzzManager, resumeFuzzAdapter);
37 resumeFuzzCapture = nullptr;
38 HDF_LOGE("%{public}s: Pause failed \n", __func__);
39 return false;
40 }
41
42 struct AudioCapture *captureFuzz = reinterpret_cast<struct AudioCapture *>(const_cast<uint8_t *>(data));
43 ret = resumeFuzzCapture->control.Resume((AudioHandle)captureFuzz);
44 if (ret == HDF_SUCCESS) {
45 result = true;
46 }
47 resumeFuzzCapture->control.Stop((AudioHandle)resumeFuzzCapture);
48 resumeFuzzAdapter->DestroyCapture(resumeFuzzAdapter, resumeFuzzCapture);
49 resumeFuzzManager->UnloadAdapter(resumeFuzzManager, resumeFuzzAdapter);
50 resumeFuzzCapture = nullptr;
51 return result;
52 }
53 }
54 }
55
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)56 extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
57 {
58 OHOS::Audio::AudioResumeCaptureFuzzTest(data, size);
59 return 0;
60 }