blob: 8237929a1781ee211f1ccf22530e5fc88f1a435b [file] [log] [blame]
Primiano Tucci4f9b6d72017-12-05 20:59:16 +00001/*
Hector Dearman39071ba2018-01-16 13:58:50 +00002 * Copyright (C) 2018 The Android Open Source Project
Primiano Tucci4f9b6d72017-12-05 20:59:16 +00003 *
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 Tucci3cbb10a2018-04-10 17:52:40 +010017#include "tools/ftrace_proto_gen/ftrace_proto_gen.h"
Primiano Tucci919ca1e2019-08-21 20:26:58 +020018#include "test/gtest_and_gmock.h"
Primiano Tucci4f9b6d72017-12-05 20:59:16 +000019
20namespace perfetto {
21namespace {
22
Hector Dearman599e3e22018-03-14 17:00:40 +000023TEST(FtraceEventParserTest, InferProtoType) {
Primiano Tucci4f9b6d72017-12-05 20:59:16 +000024 using Field = FtraceEvent::Field;
Florian Mayer616674e2018-04-20 10:36:19 +010025 EXPECT_EQ(InferProtoType(Field{"char foo[16]", 0, 16, false}).ToString(),
Hector Dearman7f37dc82018-01-25 12:25:40 +000026 "string");
Florian Mayer616674e2018-04-20 10:36:19 +010027 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 Tucci4f9b6d72017-12-05 20:59:16 +000036
Florian Mayer616674e2018-04-20 10:36:19 +010037 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 Tucci4f9b6d72017-12-05 20:59:16 +000040
Florian Mayer616674e2018-04-20 10:36:19 +010041 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 Tucci4f9b6d72017-12-05 20:59:16 +000045
Florian Mayer616674e2018-04-20 10:36:19 +010046 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 Zappone74b1f2a2018-02-16 15:51:49 +000050
Florian Mayer616674e2018-04-20 10:36:19 +010051 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 Zappone8ce30872018-03-19 17:01:15 +000055
Florian Mayer616674e2018-04-20 10:36:19 +010056 EXPECT_EQ(InferProtoType(Field{"char foo", 0, 0, false}).ToString(),
57 "string");
Primiano Tucci4f9b6d72017-12-05 20:59:16 +000058}
59
Hector Dearman599e3e22018-03-14 17:00:40 +000060TEST(FtraceEventParserTest, GenerateProtoName) {
Primiano Tucci4f9b6d72017-12-05 20:59:16 +000061 FtraceEvent input;
62 Proto output;
63 input.name = "the_snake_case_name";
64
Hector Dearman3cd7cd52019-12-04 16:07:16 +000065 GenerateProto("group", input, &output);
Primiano Tucci4f9b6d72017-12-05 20:59:16 +000066
67 EXPECT_EQ(output.name, "TheSnakeCaseNameFtraceEvent");
68}
69
70} // namespace
71} // namespace perfetto