1 /* 2 * Copyright (c) 2021 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #include <hwext/gtest-ext.h> 17 #include <hwext/gtest-tag.h> 18 19 #include "hitrace_ops.h" 20 #include "trace_ops.h" 21 22 namespace { 23 using FTRACE_NS::HitraceOps; 24 using FTRACE_NS::TraceOps; 25 using testing::ext::TestSize; 26 27 class TraceOpsTest : public ::testing::Test { 28 protected: SetUp()29 void SetUp() override {} TearDown()30 void TearDown() override {} 31 }; 32 33 /* 34 * @tc.name: GetTraceType 35 * @tc.desc: test HitraceOps::GetTraceType with normal case. 36 * @tc.type: FUNC 37 */ 38 HWTEST_F(TraceOpsTest, GetTraceType, TestSize.Level1) 39 { 40 std::unique_ptr<TraceOps> traceOps = std::make_unique<HitraceOps>(); 41 EXPECT_TRUE(traceOps->GetTraceType() == TraceOps::TraceType::HITRACE); 42 } 43 44 /* 45 * @tc.name: GetCommand 46 * @tc.desc: test HitraceOps::GetCommand with normal case. 47 * @tc.type: FUNC 48 */ 49 HWTEST_F(TraceOpsTest, GetCommand, TestSize.Level1) 50 { 51 std::unique_ptr<TraceOps> traceOps = std::make_unique<HitraceOps>(); 52 EXPECT_STREQ(traceOps->GetCommand().c_str(), "/system/bin/bytrace"); 53 } 54 55 /* 56 * @tc.name: HasCategoryNormal 57 * @tc.desc: test HitraceOps::HasCategory with normal case. 58 * @tc.type: FUNC 59 */ 60 HWTEST_F(TraceOpsTest, HasCategoryNormal, TestSize.Level1) 61 { 62 std::unique_ptr<TraceOps> traceOps = std::make_unique<HitraceOps>(); 63 EXPECT_TRUE(traceOps->HasCategory("ability")); 64 EXPECT_TRUE(traceOps->HasCategory("idle")); 65 } 66 67 /* 68 * @tc.name: HasCategoryFalse 69 * @tc.desc: test HitraceOps::HasCategory with false case. 70 * @tc.type: FUNC 71 */ 72 HWTEST_F(TraceOpsTest, HasCategoryFalse, TestSize.Level1) 73 { 74 std::unique_ptr<TraceOps> traceOps = std::make_unique<HitraceOps>(); 75 EXPECT_FALSE(traceOps->HasCategory("12345")); 76 77 traceOps = std::make_unique<TraceOps>("/system/bin/bytrace", "4567", TraceOps::TraceType::HITRACE); 78 EXPECT_FALSE(traceOps->HasCategory("sched")); 79 80 traceOps = std::make_unique<TraceOps>("1234", "bytrace", TraceOps::TraceType::HITRACE); 81 EXPECT_FALSE(traceOps->HasCategory("ability")); 82 83 traceOps = std::make_unique<TraceOps>("/system/bin/bytrace", "4567", TraceOps::TraceType::UNKNOW); 84 EXPECT_FALSE(traceOps->HasCategory("idle")); 85 86 traceOps = std::make_unique<TraceOps>("/system/bin/bytrace", "bytrace", TraceOps::TraceType::UNKNOW); 87 EXPECT_FALSE(traceOps->HasCategory("idle")); 88 } 89 90 /* 91 * @tc.name: EnableCategoriesNormal 92 * @tc.desc: test HitraceOps::EnableCategories with normal case. 93 * @tc.type: FUNC 94 */ 95 HWTEST_F(TraceOpsTest, EnableCategoriesNormal, TestSize.Level1) 96 { 97 std::unique_ptr<TraceOps> traceOps = std::make_unique<HitraceOps>(); 98 std::vector<std::string> categories; 99 categories.push_back("sched"); 100 EXPECT_TRUE(traceOps->EnableCategories(categories)); 101 categories.push_back("ability"); 102 EXPECT_TRUE(traceOps->EnableCategories(categories)); 103 categories.push_back("idle"); 104 EXPECT_TRUE(traceOps->EnableCategories(categories)); 105 } 106 107 /* 108 * @tc.name: EnableCategoriesFalse 109 * @tc.desc: test HitraceOps::EnableCategories with false case. 110 * @tc.type: FUNC 111 */ 112 HWTEST_F(TraceOpsTest, EnableCategoriesFalse, TestSize.Level1) 113 { 114 std::unique_ptr<TraceOps> traceOps = std::make_unique<HitraceOps>(); 115 std::vector<std::string> categories; 116 EXPECT_FALSE(traceOps->EnableCategories(categories)); 117 118 categories.push_back("sched"); 119 traceOps = std::make_unique<TraceOps>("/system/bin/bytrace", "4567", TraceOps::TraceType::HITRACE); 120 EXPECT_FALSE(traceOps->EnableCategories(categories)); 121 122 categories.push_back("ability"); 123 traceOps = std::make_unique<TraceOps>("1234", "bytrace", TraceOps::TraceType::HITRACE); 124 EXPECT_FALSE(traceOps->EnableCategories(categories)); 125 126 categories.push_back("idle"); 127 traceOps = std::make_unique<TraceOps>("/system/bin/bytrace", "4567", TraceOps::TraceType::UNKNOW); 128 EXPECT_FALSE(traceOps->EnableCategories(categories)); 129 130 categories.push_back("1234"); 131 traceOps = std::make_unique<TraceOps>("/system/bin/bytrace", "bytrace", TraceOps::TraceType::UNKNOW); 132 EXPECT_FALSE(traceOps->EnableCategories(categories)); 133 } 134 135 /* 136 * @tc.name: DisableCategoriesNormal 137 * @tc.desc: test HitraceOps::DisableCategories with normal case. 138 * @tc.type: FUNC 139 */ 140 HWTEST_F(TraceOpsTest, DisableCategoriesNormal, TestSize.Level1) 141 { 142 std::unique_ptr<TraceOps> traceOps = std::make_unique<HitraceOps>(); 143 EXPECT_TRUE(traceOps->DisableCategories()); 144 } 145 146 /* 147 * @tc.name: DisableCategoriesFalse 148 * @tc.desc: test HitraceOps::DisableCategories with false case. 149 * @tc.type: FUNC 150 */ 151 HWTEST_F(TraceOpsTest, DisableCategoriesFalse, TestSize.Level1) 152 { 153 std::unique_ptr<TraceOps> traceOps = std::make_unique<TraceOps>("1234", "bytrace", TraceOps::TraceType::HITRACE); 154 EXPECT_FALSE(traceOps->DisableCategories()); 155 156 traceOps = std::make_unique<TraceOps>("/system/bin/bytrace", "4567", TraceOps::TraceType::UNKNOW); 157 EXPECT_FALSE(traceOps->DisableCategories()); 158 } 159 160 /* 161 * @tc.name: IsSupportedNormal 162 * @tc.desc: test HitraceOps::IsSupported with normal case. 163 * @tc.type: FUNC 164 */ 165 HWTEST_F(TraceOpsTest, IsSupportedNormal, TestSize.Level1) 166 { 167 std::unique_ptr<TraceOps> traceOps = std::make_unique<HitraceOps>(); 168 EXPECT_TRUE(traceOps->IsSupported()); 169 } 170 171 /* 172 * @tc.name: IsSupportedFalse 173 * @tc.desc: test HitraceOps::IsSupported with false case. 174 * @tc.type: FUNC 175 */ 176 HWTEST_F(TraceOpsTest, IsSupportedFalse, TestSize.Level1) 177 { 178 std::unique_ptr<TraceOps> traceOps = std::make_unique<TraceOps>("1234", "bytrace", TraceOps::TraceType::HITRACE); 179 EXPECT_FALSE(traceOps->IsSupported()); 180 181 traceOps = std::make_unique<TraceOps>("/system/bin/bytrace", "4567", TraceOps::TraceType::UNKNOW); 182 EXPECT_TRUE(traceOps->IsSupported()); 183 184 traceOps = std::make_unique<TraceOps>("1234", "4567", TraceOps::TraceType::HITRACE); 185 EXPECT_FALSE(traceOps->IsSupported()); 186 187 traceOps = std::make_unique<TraceOps>("1234", "4567", TraceOps::TraceType::UNKNOW); 188 EXPECT_FALSE(traceOps->IsSupported()); 189 } 190 } // namespace