148f512ceSopenharmony_ci/* 248f512ceSopenharmony_ci * Copyright (c) 2024 Huawei Device Co., Ltd. 348f512ceSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 448f512ceSopenharmony_ci * you may not use this file except in compliance with the License. 548f512ceSopenharmony_ci * You may obtain a copy of the License at 648f512ceSopenharmony_ci * 748f512ceSopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 848f512ceSopenharmony_ci * 948f512ceSopenharmony_ci * Unless required by applicable law or agreed to in writing, software 1048f512ceSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 1148f512ceSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1248f512ceSopenharmony_ci * See the License for the specific language governing permissions and 1348f512ceSopenharmony_ci * limitations under the License. 1448f512ceSopenharmony_ci */ 1548f512ceSopenharmony_ci 1648f512ceSopenharmony_ci#include "PerfFileFormat_fuzzer.h" 1748f512ceSopenharmony_ci#include "perf_file_format.h" 1848f512ceSopenharmony_ci 1948f512ceSopenharmony_ciusing namespace OHOS::Developtools::HiPerf; 2048f512ceSopenharmony_ci 2148f512ceSopenharmony_cinamespace OHOS { 2248f512ceSopenharmony_cibool FuzzPerfFileFormat(const uint8_t *data, size_t size) 2348f512ceSopenharmony_ci{ 2448f512ceSopenharmony_ci char buf[DATA_MAX_SIZE] = { 0 }; 2548f512ceSopenharmony_ci if (memcpy_s(buf, sizeof(buf) - 1, data, size) != 0) { // 1 : make sure end of '\0' 2648f512ceSopenharmony_ci return false; 2748f512ceSopenharmony_ci } 2848f512ceSopenharmony_ci std::unique_ptr<PerfFileSectionString> perfFileSectionString = 2948f512ceSopenharmony_ci std::make_unique<PerfFileSectionString>(FEATURE::HIPERF_FILES_SYMBOL, buf, size); 3048f512ceSopenharmony_ci perfFileSectionString->GetBinary(buf, size); 3148f512ceSopenharmony_ci std::unique_ptr<PerfFileSectionNrCpus> perfFileSectionNrCpus = 3248f512ceSopenharmony_ci std::make_unique<PerfFileSectionNrCpus>(FEATURE::HIPERF_FILES_SYMBOL, buf, size); 3348f512ceSopenharmony_ci perfFileSectionNrCpus->GetBinary(buf, size); 3448f512ceSopenharmony_ci std::unique_ptr<PerfFileSectionU64> perfFileSectionU64 = 3548f512ceSopenharmony_ci std::make_unique<PerfFileSectionU64>(FEATURE::HIPERF_FILES_SYMBOL, buf, size); 3648f512ceSopenharmony_ci perfFileSectionU64->GetBinary(buf, size); 3748f512ceSopenharmony_ci return 0; 3848f512ceSopenharmony_ci} 3948f512ceSopenharmony_ci} // namespace OHOS 4048f512ceSopenharmony_ci 4148f512ceSopenharmony_ci/* Fuzzer entry point */ 4248f512ceSopenharmony_ciextern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) 4348f512ceSopenharmony_ci{ 4448f512ceSopenharmony_ci/* Run your code on data */ 4548f512ceSopenharmony_ci#ifdef DEBUG_HIPERF_FUZZ 4648f512ceSopenharmony_ci ScopeDebugLevel mix(LEVEL_DEBUG, true); 4748f512ceSopenharmony_ci DebugLogger::GetInstance()->Disable(false); 4848f512ceSopenharmony_ci#else 4948f512ceSopenharmony_ci OHOS::Developtools::HiPerf::StdoutRecord noStdOut("/dev/null", "w"); 5048f512ceSopenharmony_ci#endif 5148f512ceSopenharmony_ci 5248f512ceSopenharmony_ci OHOS::FuzzPerfFileFormat(data, size); 5348f512ceSopenharmony_ci return 0; 5448f512ceSopenharmony_ci} 55