Home | History | Annotate | Download | only in ftrace_reader
      1 /*
      2  * Copyright (C) 2017 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/ftrace_reader/event_info.h"
     18 
     19 #include "gtest/gtest.h"
     20 
     21 namespace perfetto {
     22 namespace {
     23 
     24 TEST(EventInfoTest, GetStaticEventInfoSanityCheck) {
     25   std::vector<Event> events = GetStaticEventInfo();
     26   for (const Event& event : events) {
     27     // For each event the following fields should be filled
     28     // statically:
     29 
     30     // Non-empty name, group, and proto field id.
     31     ASSERT_TRUE(event.name);
     32     ASSERT_TRUE(event.group);
     33     ASSERT_TRUE(event.proto_field_id);
     34 
     35     // Ftrace id and size should be zeroed.
     36     ASSERT_FALSE(event.ftrace_event_id);
     37     ASSERT_FALSE(event.size);
     38 
     39     for (const Field& field : event.fields) {
     40       // Non-empty name, proto field id, and proto field type.
     41       ASSERT_TRUE(field.ftrace_name);
     42       ASSERT_TRUE(field.proto_field_id);
     43       ASSERT_TRUE(field.proto_field_type);
     44 
     45       // Other fields should be zeroed.
     46       ASSERT_FALSE(field.ftrace_offset);
     47       ASSERT_FALSE(field.ftrace_size);
     48       ASSERT_FALSE(field.strategy);
     49       ASSERT_FALSE(field.ftrace_type);
     50     }
     51   }
     52 }
     53 
     54 TEST(EventInfoTest, GetStaticCommonFieldsInfoSanityCheck) {
     55   std::vector<Field> fields = GetStaticCommonFieldsInfo();
     56   for (const Field& field : fields) {
     57     // Non-empty name, group, and proto field id.
     58     ASSERT_TRUE(field.ftrace_name);
     59     ASSERT_TRUE(field.proto_field_id);
     60     ASSERT_TRUE(field.proto_field_type);
     61 
     62     // Other fields should be zeroed.
     63     ASSERT_FALSE(field.ftrace_offset);
     64     ASSERT_FALSE(field.ftrace_size);
     65     ASSERT_FALSE(field.strategy);
     66     ASSERT_FALSE(field.ftrace_type);
     67   }
     68 }
     69 
     70 TEST(EventInfoTest, SetTranslationStrategySanityCheck) {
     71   TranslationStrategy strategy = kUint32ToUint32;
     72   ASSERT_FALSE(SetTranslationStrategy(kFtraceCString, kProtoUint64, &strategy));
     73   ASSERT_EQ(strategy, kUint32ToUint32);
     74   ASSERT_TRUE(SetTranslationStrategy(kFtraceCString, kProtoString, &strategy));
     75   ASSERT_EQ(strategy, kCStringToString);
     76   ASSERT_TRUE(SetTranslationStrategy(kFtracePid32, kProtoInt32, &strategy));
     77   ASSERT_EQ(strategy, kPid32ToInt32);
     78   ASSERT_TRUE(SetTranslationStrategy(kFtraceInode32, kProtoUint64, &strategy));
     79   ASSERT_EQ(strategy, kInode32ToUint64);
     80   ASSERT_TRUE(SetTranslationStrategy(kFtraceInode64, kProtoUint64, &strategy));
     81   ASSERT_EQ(strategy, kInode64ToUint64);
     82   ASSERT_TRUE(SetTranslationStrategy(kFtraceDevId32, kProtoUint64, &strategy));
     83   ASSERT_EQ(strategy, kDevId32ToUint64);
     84   ASSERT_TRUE(SetTranslationStrategy(kFtraceDevId64, kProtoUint64, &strategy));
     85   ASSERT_EQ(strategy, kDevId64ToUint64);
     86   ASSERT_TRUE(
     87       SetTranslationStrategy(kFtraceCommonPid32, kProtoInt32, &strategy));
     88   ASSERT_EQ(strategy, kCommonPid32ToInt32);
     89 }
     90 
     91 }  // namespace
     92 }  // namespace perfetto
     93