xref: /aosp_15_r20/external/perfetto/src/tools/ftrace_proto_gen/ftrace_proto_gen_unittest.cc (revision 6dbdd20afdafa5e3ca9b8809fa73465d530080dc)
1 /*
2  * Copyright (C) 2018 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #include "src/tools/ftrace_proto_gen/ftrace_proto_gen.h"
18 #include "test/gtest_and_gmock.h"
19 
20 namespace perfetto {
21 namespace {
22 
TEST(FtraceEventParserTest,InferProtoType)23 TEST(FtraceEventParserTest, InferProtoType) {
24   using Field = FtraceEvent::Field;
25   EXPECT_EQ(InferProtoType(Field{"char foo[16]", 0, 16, false}).ToString(),
26             "string");
27   EXPECT_EQ(InferProtoType(Field{"char bar_42[64]", 0, 64, false}).ToString(),
28             "string");
29   EXPECT_EQ(
30       InferProtoType(Field{"__data_loc char[] foo", 0, 4, false}).ToString(),
31       "string");
32   EXPECT_EQ(InferProtoType(Field{"char[] foo", 0, 8, false}).ToString(),
33             "string");
34   EXPECT_EQ(InferProtoType(Field{"char * foo", 0, 8, false}).ToString(),
35             "string");
36 
37   EXPECT_EQ(InferProtoType(Field{"int foo", 0, 4, true}).ToString(), "int32");
38   EXPECT_EQ(InferProtoType(Field{"s32 signal", 50, 4, true}).ToString(),
39             "int32");
40 
41   EXPECT_EQ(InferProtoType(Field{"unsigned int foo", 0, 4, false}).ToString(),
42             "uint32");
43   EXPECT_EQ(InferProtoType(Field{"u32 control_freq", 44, 4, false}).ToString(),
44             "uint32");
45 
46   EXPECT_EQ(InferProtoType(Field{"ino_t foo", 0, 4, false}).ToString(),
47             "uint64");
48   EXPECT_EQ(InferProtoType(Field{"ino_t foo", 0, 8, false}).ToString(),
49             "uint64");
50 
51   EXPECT_EQ(InferProtoType(Field{"dev_t foo", 0, 4, false}).ToString(),
52             "uint64");
53   EXPECT_EQ(InferProtoType(Field{"dev_t foo", 0, 8, false}).ToString(),
54             "uint64");
55 
56   EXPECT_EQ(InferProtoType(Field{"char foo", 0, 0, false}).ToString(),
57             "string");
58 
59   EXPECT_EQ(InferProtoType(Field{"bool foo", 0, 8, true}).ToString(), "uint32");
60   EXPECT_EQ(InferProtoType(Field{"bool foo", 0, 8, false}).ToString(),
61             "uint32");
62 
63   EXPECT_EQ(
64       InferProtoType(Field{"unsigned long args[6]", 0, 0, false}).ToString(),
65       "uint64");
66 }
67 
TEST(FtraceEventParserTest,EventNameToProtoName)68 TEST(FtraceEventParserTest, EventNameToProtoName) {
69   std::string s = EventNameToProtoName("group", "the_snake_case_name");
70   EXPECT_EQ(s, "TheSnakeCaseNameFtraceEvent");
71 }
72 
73 }  // namespace
74 }  // namespace perfetto
75