• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include "hpae_dfx_tree.h"
17 #include "audio_log.h"
18 #include "../fuzz_utils.h"
19 
20 namespace OHOS {
21 namespace AudioStandard {
22 using namespace std;
23 using namespace HPAE;
24 
25 FuzzUtils &g_fuzzUtils = FuzzUtils::GetInstance();
26 const size_t THRESHOLD = 10;
27 typedef void (*TestFuncs)();
28 
LevelOrderTraversalFuzzTest()29 void LevelOrderTraversalFuzzTest()
30 {
31     std::shared_ptr<HpaeDfxTree> hpaeDfxTree = std::make_shared<HpaeDfxTree>();
32     CHECK_AND_RETURN(hpaeDfxTree != nullptr);
33     uint32_t parentNodeId =  g_fuzzUtils.GetData<uint32_t>();
34     HpaeDfxNodeInfo info = {
35         .nodeId = g_fuzzUtils.GetData<uint32_t>(),
36     };
37     hpaeDfxTree->Insert(parentNodeId, info);
38     hpaeDfxTree->LevelOrderTraversal();
39 }
40 
PrintNodeInfoFuzzTest()41 void PrintNodeInfoFuzzTest()
42 {
43     std::shared_ptr<HpaeDfxTree> hpaeDfxTree = std::make_shared<HpaeDfxTree>();
44     CHECK_AND_RETURN(hpaeDfxTree != nullptr);
45     string outStr = "test";
46     HpaeDfxNodeInfo nodeInfo = {
47         .nodeName = "test",
48         .sessionId = g_fuzzUtils.GetData<uint32_t>(),
49         .nodeId = g_fuzzUtils.GetData<uint32_t>(),
50         .samplingRate = g_fuzzUtils.GetData< AudioSamplingRate>(),
51         .channels = g_fuzzUtils.GetData<AudioChannel>(),
52         .format = g_fuzzUtils.GetData<AudioSampleFormat>(),
53         .frameLen = g_fuzzUtils.GetData<uint32_t>(),
54         .sceneType = g_fuzzUtils.GetData<HpaeProcessorType>(),
55     };
56 
57     hpaeDfxTree->PrintNodeInfo(outStr, nodeInfo);
58 }
59 vector<TestFuncs> g_testFuncs = {
60     LevelOrderTraversalFuzzTest,
61     PrintNodeInfoFuzzTest,
62 };
63 } // namespace AudioStandard
64 } // namesapce OHOS
65 
66 /* Fuzzer entry point */
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)67 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
68 {
69     if (size < OHOS::AudioStandard::THRESHOLD) {
70         return 0;
71     }
72 
73     OHOS::AudioStandard::g_fuzzUtils.fuzzTest(data, size, OHOS::AudioStandard::g_testFuncs);
74     return 0;
75 }
76