/* * Copyright (c) 2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include "hisyseventmanager_fuzzer.h" #include #include #include #include "hisysevent_manager.h" namespace OHOS { namespace HiviewDFX { namespace { class TestQueryCallback : public HiSysEventQueryCallback { public: TestQueryCallback() {} virtual ~TestQueryCallback() {} void OnQuery(std::shared_ptr> sysEvents) override {} void OnComplete(int32_t reason, int32_t total) override {} }; void HiSysEventRecordTest(const HiSysEventRecord& record, const std::string& data) { (void)record.AsJson(); (void)record.GetDomain(); (void)record.GetEventName(); (void)record.GetLevel(); (void)record.GetTag(); (void)record.GetTimeZone(); (void)record.GetEventType(); (void)record.GetTraceFlag(); (void)record.GetPid(); (void)record.GetTid(); (void)record.GetUid(); (void)record.GetPspanId(); (void)record.GetSpanId(); (void)record.GetTime(); (void)record.GetTraceId(); std::vector params; record.GetParamNames(params); int64_t intValue = 0; (void)record.GetParamValue(data, intValue); uint64_t uintValue = 0; (void)record.GetParamValue(data, uintValue); double dValue = 0; (void)record.GetParamValue(data, dValue); std::string strValue; (void)record.GetParamValue(data, strValue); std::vector intValues; (void)record.GetParamValue(data, intValues); std::vector uintValues; (void)record.GetParamValue(data, uintValues); std::vector dValues; (void)record.GetParamValue(data, dValues); std::vector strValues; (void)record.GetParamValue(data, strValues); } void HiSysEventQueryTest(const std::string& strData, int64_t intData) { auto callback = std::make_shared(); QueryArg arg(0, intData, intData); std::vector rules = { QueryRule(strData, {strData}) }; (void)HiSysEventManager::Query(arg, rules, callback); } } void HiSysEventRecordFuzzTest(const uint8_t* data, size_t size) { std::string strData((const char*) data, size); const std::string jsonStr = R"~({"domain_":"test_domain","name_":"test_name"})~"; HiSysEventRecord record(jsonStr); HiSysEventRecordTest(record, strData); } void HiSysEventQueryFuzzTest(const uint8_t* data, size_t size) { std::string strData((const char*) data, size); int64_t intData = static_cast(*data); HiSysEventQueryTest(strData, intData); } } // namespace HiviewDFX } // namespace OHOS /* Fuzzer entry point */ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { /* Run your code on data */ OHOS::HiviewDFX::HiSysEventRecordFuzzTest(data, size); OHOS::HiviewDFX::HiSysEventQueryFuzzTest(data, size); return 0; }