• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "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 
TEST(FtraceEventParserTest,GenerateProtoName)60 TEST(FtraceEventParserTest, GenerateProtoName) {
61   FtraceEvent input;
62   Proto output;
63   input.name = "the_snake_case_name";
64 
65   GenerateProto("group", input, &output);
66 
67   EXPECT_EQ(output.name, "TheSnakeCaseNameFtraceEvent");
68 }
69 
70 }  // namespace
71 }  // namespace perfetto
72