Primiano Tucci | 4f9b6d7 | 2017-12-05 20:59:16 +0000 | [diff] [blame] | 1 | /* |
Hector Dearman | 39071ba | 2018-01-16 13:58:50 +0000 | [diff] [blame] | 2 | * Copyright (C) 2018 The Android Open Source Project |
Primiano Tucci | 4f9b6d7 | 2017-12-05 20:59:16 +0000 | [diff] [blame] | 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 | |
Primiano Tucci | 3cbb10a | 2018-04-10 17:52:40 +0100 | [diff] [blame] | 17 | #include "tools/ftrace_proto_gen/ftrace_proto_gen.h" |
Primiano Tucci | 919ca1e | 2019-08-21 20:26:58 +0200 | [diff] [blame] | 18 | #include "test/gtest_and_gmock.h" |
Primiano Tucci | 4f9b6d7 | 2017-12-05 20:59:16 +0000 | [diff] [blame] | 19 | |
| 20 | namespace perfetto { |
| 21 | namespace { |
| 22 | |
Hector Dearman | 599e3e2 | 2018-03-14 17:00:40 +0000 | [diff] [blame] | 23 | TEST(FtraceEventParserTest, InferProtoType) { |
Primiano Tucci | 4f9b6d7 | 2017-12-05 20:59:16 +0000 | [diff] [blame] | 24 | using Field = FtraceEvent::Field; |
Florian Mayer | 616674e | 2018-04-20 10:36:19 +0100 | [diff] [blame] | 25 | EXPECT_EQ(InferProtoType(Field{"char foo[16]", 0, 16, false}).ToString(), |
Hector Dearman | 7f37dc8 | 2018-01-25 12:25:40 +0000 | [diff] [blame] | 26 | "string"); |
Florian Mayer | 616674e | 2018-04-20 10:36:19 +0100 | [diff] [blame] | 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"); |
Primiano Tucci | 4f9b6d7 | 2017-12-05 20:59:16 +0000 | [diff] [blame] | 36 | |
Florian Mayer | 616674e | 2018-04-20 10:36:19 +0100 | [diff] [blame] | 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"); |
Primiano Tucci | 4f9b6d7 | 2017-12-05 20:59:16 +0000 | [diff] [blame] | 40 | |
Florian Mayer | 616674e | 2018-04-20 10:36:19 +0100 | [diff] [blame] | 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"); |
Primiano Tucci | 4f9b6d7 | 2017-12-05 20:59:16 +0000 | [diff] [blame] | 45 | |
Florian Mayer | 616674e | 2018-04-20 10:36:19 +0100 | [diff] [blame] | 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"); |
Anna Zappone | 74b1f2a | 2018-02-16 15:51:49 +0000 | [diff] [blame] | 50 | |
Florian Mayer | 616674e | 2018-04-20 10:36:19 +0100 | [diff] [blame] | 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"); |
Anna Zappone | 8ce3087 | 2018-03-19 17:01:15 +0000 | [diff] [blame] | 55 | |
Florian Mayer | 616674e | 2018-04-20 10:36:19 +0100 | [diff] [blame] | 56 | EXPECT_EQ(InferProtoType(Field{"char foo", 0, 0, false}).ToString(), |
| 57 | "string"); |
Primiano Tucci | 4f9b6d7 | 2017-12-05 20:59:16 +0000 | [diff] [blame] | 58 | } |
| 59 | |
Hector Dearman | 599e3e2 | 2018-03-14 17:00:40 +0000 | [diff] [blame] | 60 | TEST(FtraceEventParserTest, GenerateProtoName) { |
Primiano Tucci | 4f9b6d7 | 2017-12-05 20:59:16 +0000 | [diff] [blame] | 61 | FtraceEvent input; |
| 62 | Proto output; |
| 63 | input.name = "the_snake_case_name"; |
| 64 | |
Hector Dearman | 3cd7cd5 | 2019-12-04 16:07:16 +0000 | [diff] [blame] | 65 | GenerateProto("group", input, &output); |
Primiano Tucci | 4f9b6d7 | 2017-12-05 20:59:16 +0000 | [diff] [blame] | 66 | |
| 67 | EXPECT_EQ(output.name, "TheSnakeCaseNameFtraceEvent"); |
| 68 | } |
| 69 | |
| 70 | } // namespace |
| 71 | } // namespace perfetto |