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 #include <cstddef>
16 #include <cstdint>
17 #include <thread>
18 #include <vector>
19 #include "intell_voice_log.h"
20 #include "intell_voice_manager_test.h"
21 #include "enroll_engine_test.h"
22 #include "wakeup_engine_test.h"
23
24 #define LOG_TAG "IntellVoiceManagerFuzzer"
25
26 using namespace std;
27 using namespace OHOS;
28 using namespace OHOS::IntellVoiceFuzzTest;
29
30 constexpr int THREAD_NUM = 12;
31
32 /* Fuzzer entry point */
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)33 extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
34 {
35 if (data == nullptr || size == 0) {
36 INTELL_VOICE_LOG_INFO("intell voice test error input");
37 return 0;
38 }
39 /* Run your code on data */
40 vector<thread> threads(THREAD_NUM);
41 for (int i = 0; i < THREAD_NUM; i++) {
42 threads[i] = std::thread([i, data, size]() {
43 INTELL_VOICE_LOG_INFO("thread: %{public}d start", i);
44 TestIntellVoiceRandomFuzzer(data, size);
45 TestEnrollEngineRandomFuzzer(data, size);
46 TestWakeupEngineRandomFuzzer(data, size);
47 INTELL_VOICE_LOG_INFO("thread: %{public}d end", i);
48 });
49 }
50 for (int i = 0; i < THREAD_NUM; i++) {
51 threads[i].join();
52 }
53 return 0;
54 }