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 
16 #ifndef FAULTLOGGERD_FUZZERTEST_COMMON_H
17 #define FAULTLOGGERD_FUZZERTEST_COMMON_H
18 
19 #include <cstdint>
20 #include <iostream>
21 #include <string>
22 #include <vector>
23 
24 #include <hitrace_meter.h>
25 #include "securec.h"
26 
27 namespace OHOS {
28 namespace HiviewDFX {
29 template<typename T>
StreamToValueInfo(const uint8_t* data, T value)30 void StreamToValueInfo(const uint8_t* data, T value)
31 {
32     do {
33         errno_t err = memcpy_s(&(value), sizeof(value), (data), sizeof(value));
34         if (err != 0) {
35             std::cout << "memcpy_s return value is abnormal!" << std::endl;
36         }
37         (data) += sizeof(value);
38     } while (0);
39 }
40 
GenerateTagStr(const uint64_t tags, std::string& tagStr)41 void GenerateTagStr(const uint64_t tags, std::string& tagStr)
42 {
43     if (tags & HITRACE_TAG_SECURITY) {
44         tagStr += " security";
45     }
46     if (tags & HITRACE_TAG_ANIMATION) {
47         tagStr += " animation";
48     }
49     if (tags & HITRACE_TAG_MUSL) {
50         tagStr += " musl";
51     }
52     if (tags & HITRACE_TAG_FFRT) {
53         tagStr += " ffrt";
54     }
55     if (tags & HITRACE_TAG_OHOS) {
56         tagStr += " ohos";
57     }
58     if (tags & HITRACE_TAG_APP) {
59         tagStr += " app";
60     }
61     if (tags & HITRACE_TAG_HDCD) {
62         tagStr += " hdcd";
63     }
64     if (tags & HITRACE_TAG_ACE) {
65         tagStr += " ace";
66     }
67     if (tags & HITRACE_TAG_POWER) {
68         tagStr += " power";
69     }
70 }
71 
GenerateTagVec(const uint64_t tags, std::vector<std::string>& tagVec)72 void GenerateTagVec(const uint64_t tags, std::vector<std::string>& tagVec)
73 {
74     if (tags & HITRACE_TAG_SECURITY) {
75         tagVec.push_back("security");
76     }
77     if (tags & HITRACE_TAG_ANIMATION) {
78         tagVec.push_back("animation");
79     }
80     if (tags & HITRACE_TAG_MUSL) {
81         tagVec.push_back("musl");
82     }
83     if (tags & HITRACE_TAG_FFRT) {
84         tagVec.push_back("ffrt");
85     }
86     if (tags & HITRACE_TAG_OHOS) {
87         tagVec.push_back("ohos");
88     }
89     if (tags & HITRACE_TAG_APP) {
90         tagVec.push_back("app");
91     }
92     if (tags & HITRACE_TAG_HDCD) {
93         tagVec.push_back("hdcd");
94     }
95     if (tags & HITRACE_TAG_ACE) {
96         tagVec.push_back("ace");
97     }
98     if (tags & HITRACE_TAG_POWER) {
99         tagVec.push_back("power");
100     }
101 }
102 }
103 }
104 #endif
105