Home | History | Annotate | Download | only in ftrace_proto_gen
      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 "gtest/gtest.h"
     19 
     20 namespace perfetto {
     21 namespace {
     22 
     23 TEST(FtraceEventParserTest, InferProtoType) {
     24   using Field = FtraceEvent::Field;
     25   EXPECT_EQ(InferProtoType(Field{"char foo[16]", 0, 16, false}), "string");
     26   EXPECT_EQ(InferProtoType(Field{"char bar_42[64]", 0, 64, false}), "string");
     27   EXPECT_EQ(InferProtoType(Field{"__data_loc char[] foo", 0, 4, false}),
     28             "string");
     29   EXPECT_EQ(InferProtoType(Field{"char[] foo", 0, 8, false}), "string");
     30   EXPECT_EQ(InferProtoType(Field{"char * foo", 0, 8, false}), "string");
     31 
     32   EXPECT_EQ(InferProtoType(Field{"int foo", 0, 4, true}), "int32");
     33   EXPECT_EQ(InferProtoType(Field{"s32 signal", 50, 4, true}), "int32");
     34 
     35   EXPECT_EQ(InferProtoType(Field{"unsigned int foo", 0, 4, false}), "uint32");
     36   EXPECT_EQ(InferProtoType(Field{"u32 control_freq", 44, 4, false}), "uint32");
     37 
     38   EXPECT_EQ(InferProtoType(Field{"ino_t foo", 0, 4, false}), "uint64");
     39   EXPECT_EQ(InferProtoType(Field{"ino_t foo", 0, 8, false}), "uint64");
     40 
     41   EXPECT_EQ(InferProtoType(Field{"dev_t foo", 0, 4, false}), "uint64");
     42   EXPECT_EQ(InferProtoType(Field{"dev_t foo", 0, 8, false}), "uint64");
     43 
     44   EXPECT_EQ(InferProtoType(Field{"char foo", 0, 0, false}), "string");
     45 }
     46 
     47 TEST(FtraceEventParserTest, GenerateProtoName) {
     48   FtraceEvent input;
     49   Proto output;
     50   input.name = "the_snake_case_name";
     51 
     52   GenerateProto(input, &output);
     53 
     54   EXPECT_EQ(output.name, "TheSnakeCaseNameFtraceEvent");
     55 }
     56 
     57 }  // namespace
     58 }  // namespace perfetto
     59