1b0e7dd80Sopenharmony_ci/* 2b0e7dd80Sopenharmony_ci * Copyright (c) 2024 Huawei Device Co., Ltd. 3b0e7dd80Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 4b0e7dd80Sopenharmony_ci * you may not use this file except in compliance with the License. 5b0e7dd80Sopenharmony_ci * You may obtain a copy of the License at 6b0e7dd80Sopenharmony_ci * 7b0e7dd80Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 8b0e7dd80Sopenharmony_ci * 9b0e7dd80Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 10b0e7dd80Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 11b0e7dd80Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12b0e7dd80Sopenharmony_ci * See the License for the specific language governing permissions and 13b0e7dd80Sopenharmony_ci * limitations under the License. 14b0e7dd80Sopenharmony_ci */ 15b0e7dd80Sopenharmony_ci 16b0e7dd80Sopenharmony_ci#ifndef FAULTLOGGERD_FUZZERTEST_COMMON_H 17b0e7dd80Sopenharmony_ci#define FAULTLOGGERD_FUZZERTEST_COMMON_H 18b0e7dd80Sopenharmony_ci 19b0e7dd80Sopenharmony_ci#include <cstdint> 20b0e7dd80Sopenharmony_ci#include <iostream> 21b0e7dd80Sopenharmony_ci#include <string> 22b0e7dd80Sopenharmony_ci#include <vector> 23b0e7dd80Sopenharmony_ci 24b0e7dd80Sopenharmony_ci#include <hitrace_meter.h> 25b0e7dd80Sopenharmony_ci#include "securec.h" 26b0e7dd80Sopenharmony_ci 27b0e7dd80Sopenharmony_cinamespace OHOS { 28b0e7dd80Sopenharmony_cinamespace HiviewDFX { 29b0e7dd80Sopenharmony_citemplate<typename T> 30b0e7dd80Sopenharmony_civoid StreamToValueInfo(const uint8_t* data, T value) 31b0e7dd80Sopenharmony_ci{ 32b0e7dd80Sopenharmony_ci do { 33b0e7dd80Sopenharmony_ci errno_t err = memcpy_s(&(value), sizeof(value), (data), sizeof(value)); 34b0e7dd80Sopenharmony_ci if (err != 0) { 35b0e7dd80Sopenharmony_ci std::cout << "memcpy_s return value is abnormal!" << std::endl; 36b0e7dd80Sopenharmony_ci } 37b0e7dd80Sopenharmony_ci (data) += sizeof(value); 38b0e7dd80Sopenharmony_ci } while (0); 39b0e7dd80Sopenharmony_ci} 40b0e7dd80Sopenharmony_ci 41b0e7dd80Sopenharmony_civoid GenerateTagStr(const uint64_t tags, std::string& tagStr) 42b0e7dd80Sopenharmony_ci{ 43b0e7dd80Sopenharmony_ci if (tags & HITRACE_TAG_SECURITY) { 44b0e7dd80Sopenharmony_ci tagStr += " security"; 45b0e7dd80Sopenharmony_ci } 46b0e7dd80Sopenharmony_ci if (tags & HITRACE_TAG_ANIMATION) { 47b0e7dd80Sopenharmony_ci tagStr += " animation"; 48b0e7dd80Sopenharmony_ci } 49b0e7dd80Sopenharmony_ci if (tags & HITRACE_TAG_MUSL) { 50b0e7dd80Sopenharmony_ci tagStr += " musl"; 51b0e7dd80Sopenharmony_ci } 52b0e7dd80Sopenharmony_ci if (tags & HITRACE_TAG_FFRT) { 53b0e7dd80Sopenharmony_ci tagStr += " ffrt"; 54b0e7dd80Sopenharmony_ci } 55b0e7dd80Sopenharmony_ci if (tags & HITRACE_TAG_OHOS) { 56b0e7dd80Sopenharmony_ci tagStr += " ohos"; 57b0e7dd80Sopenharmony_ci } 58b0e7dd80Sopenharmony_ci if (tags & HITRACE_TAG_APP) { 59b0e7dd80Sopenharmony_ci tagStr += " app"; 60b0e7dd80Sopenharmony_ci } 61b0e7dd80Sopenharmony_ci if (tags & HITRACE_TAG_HDCD) { 62b0e7dd80Sopenharmony_ci tagStr += " hdcd"; 63b0e7dd80Sopenharmony_ci } 64b0e7dd80Sopenharmony_ci if (tags & HITRACE_TAG_ACE) { 65b0e7dd80Sopenharmony_ci tagStr += " ace"; 66b0e7dd80Sopenharmony_ci } 67b0e7dd80Sopenharmony_ci if (tags & HITRACE_TAG_POWER) { 68b0e7dd80Sopenharmony_ci tagStr += " power"; 69b0e7dd80Sopenharmony_ci } 70b0e7dd80Sopenharmony_ci} 71b0e7dd80Sopenharmony_ci 72b0e7dd80Sopenharmony_civoid GenerateTagVec(const uint64_t tags, std::vector<std::string>& tagVec) 73b0e7dd80Sopenharmony_ci{ 74b0e7dd80Sopenharmony_ci if (tags & HITRACE_TAG_SECURITY) { 75b0e7dd80Sopenharmony_ci tagVec.push_back("security"); 76b0e7dd80Sopenharmony_ci } 77b0e7dd80Sopenharmony_ci if (tags & HITRACE_TAG_ANIMATION) { 78b0e7dd80Sopenharmony_ci tagVec.push_back("animation"); 79b0e7dd80Sopenharmony_ci } 80b0e7dd80Sopenharmony_ci if (tags & HITRACE_TAG_MUSL) { 81b0e7dd80Sopenharmony_ci tagVec.push_back("musl"); 82b0e7dd80Sopenharmony_ci } 83b0e7dd80Sopenharmony_ci if (tags & HITRACE_TAG_FFRT) { 84b0e7dd80Sopenharmony_ci tagVec.push_back("ffrt"); 85b0e7dd80Sopenharmony_ci } 86b0e7dd80Sopenharmony_ci if (tags & HITRACE_TAG_OHOS) { 87b0e7dd80Sopenharmony_ci tagVec.push_back("ohos"); 88b0e7dd80Sopenharmony_ci } 89b0e7dd80Sopenharmony_ci if (tags & HITRACE_TAG_APP) { 90b0e7dd80Sopenharmony_ci tagVec.push_back("app"); 91b0e7dd80Sopenharmony_ci } 92b0e7dd80Sopenharmony_ci if (tags & HITRACE_TAG_HDCD) { 93b0e7dd80Sopenharmony_ci tagVec.push_back("hdcd"); 94b0e7dd80Sopenharmony_ci } 95b0e7dd80Sopenharmony_ci if (tags & HITRACE_TAG_ACE) { 96b0e7dd80Sopenharmony_ci tagVec.push_back("ace"); 97b0e7dd80Sopenharmony_ci } 98b0e7dd80Sopenharmony_ci if (tags & HITRACE_TAG_POWER) { 99b0e7dd80Sopenharmony_ci tagVec.push_back("power"); 100b0e7dd80Sopenharmony_ci } 101b0e7dd80Sopenharmony_ci} 102b0e7dd80Sopenharmony_ci} 103b0e7dd80Sopenharmony_ci} 104b0e7dd80Sopenharmony_ci#endif 105