• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #ifndef LOG_TAG
16 #define LOG_TAG "AudioFuzzTest"
17 #endif
18 
19 #include <iostream>
20 #include <cstddef>
21 #include <cstdint>
22 #include "audio_hdi_log.h"
23 #include "audio_common_converter.h"
24 #include "message_parcel.h"
25 #include "audio_info.h"
26 #include "audio_source_type.h"
27 #include "audio_ring_cache.h"
28 #include "audio_thread_task.h"
29 using namespace std;
30 
31 namespace OHOS {
32 namespace AudioStandard {
33 const int32_t LIMITSIZE = 4;
34 static const std::string THREAD_NAME = "FuzzTestThreadName";
35 
AudioThreadTaskFuzzTest(const uint8_t * rawData,size_t size)36 void AudioThreadTaskFuzzTest(const uint8_t* rawData, size_t size)
37 {
38     if (rawData == nullptr || size < LIMITSIZE) {
39         return;
40     }
41     std::unique_ptr<AudioThreadTask> audioThreadTask;
42     audioThreadTask = std::make_unique<AudioThreadTask>(THREAD_NAME);
43     auto myJob = []() {
44         AUDIO_INFO_LOG("Hello Fuzz Test!");
45     };
46     audioThreadTask->RegisterJob(std::move(myJob));
47     audioThreadTask->Start();
48     audioThreadTask->CheckThreadIsRunning();
49     audioThreadTask->Pause();
50     audioThreadTask->Start();
51     audioThreadTask->PauseAsync();
52     audioThreadTask->Start();
53     audioThreadTask->StopAsync();
54     audioThreadTask->Start();
55     audioThreadTask->Stop();
56 }
57 
58 } // namespace AudioStandard
59 } // namesapce 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::AudioStandard::AudioThreadTaskFuzzTest(data, size);
66     return 0;
67 }
68