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 <string> 17 #include <thread> 18 #include <vector> 19 #include <gtest/gtest.h> 20 #include "sp_utils.h" 21 #include "RAM.h" 22 #include "GPU.h" 23 #include "CPU.h" 24 #include "FPS.h" 25 #include "Temperature.h" 26 #include "Power.h" 27 #include "Capture.h" 28 #include "Network.h" 29 #include "profiler_fps.h" 30 #include "parse_click_complete_trace.h" 31 #include "parse_click_response_trace.h" 32 #include "parse_slide_fps_trace.h" 33 #include "DDR.h" 34 #include "navigation.h" 35 using namespace testing::ext; 36 using namespace std; 37 38 namespace OHOS { 39 namespace SmartPerf { 40 class SPdaemonTest : public testing::Test { 41 public: SetUpTestCase()42 static void SetUpTestCase() {} TearDownTestCase()43 static void TearDownTestCase() {} 44 SetUp()45 void SetUp() {} TearDown()46 void TearDown() {} 47 }; 48 49 /** 50 * @tc.name: CpuTestCase 51 * @tc.desc: Test CPU 52 * @tc.type: FUNC 53 */ 54 HWTEST_F(SPdaemonTest, CpuTestCase, TestSize.Level1) 55 { 56 CPU &cpu = CPU::GetInstance(); 57 std::string packName = "ohos.samples.ecg"; 58 59 std::map<std::string, std::string> cpuItemData = cpu.ItemData(); 60 cpu.SetPackageName(packName); 61 std::vector<CpuFreqs> cpuFreqs = cpu.GetCpuFreq(); 62 std::vector<CpuUsageInfos> getCpuUsage = cpu.GetCpuUsage(); 63 std::map<std::string, std::string> getSysProcessCpuLoad = cpu.GetSysProcessCpuLoad(); 64 65 std::string cmd = "SP_daemon -N 1 -PKG ohos.samples.ecg -c"; 66 std::string result = ""; 67 bool flag = false; 68 auto ret = SPUtils::LoadCmd(cmd, result); 69 std::string::size_type strOne = result.find("cpu0Usage"); 70 std::string::size_type strTwo = result.find("cpu0idleUsage"); 71 if ((strOne != result.npos) && (strTwo != result.npos)) { 72 flag = true; 73 } 74 EXPECT_EQ(ret, true); 75 EXPECT_TRUE(flag); 76 } 77 78 /** 79 * @tc.name: GpuTestCase 80 * @tc.desc: Test GPU 81 * @tc.type: FUNC 82 */ 83 HWTEST_F(SPdaemonTest, GpuTestCase, TestSize.Level1) 84 { 85 GPU &gpu = GPU::GetInstance(); 86 int getGpuFreq = 0; 87 float getGpuLoad = 0.0; 88 std::map<std::string, std::string> gpuItemData = gpu.ItemData(); 89 getGpuFreq = gpu.GetGpuFreq(); 90 getGpuLoad = gpu.GetGpuLoad(); 91 92 std::string cmd = "SP_daemon -N 1 -g"; 93 std::string result = ""; 94 bool flag = false; 95 auto ret = SPUtils::LoadCmd(cmd, result); 96 std::string::size_type strOne = result.find("gpuFrequency"); 97 std::string::size_type strTwo = result.find("gpuLoad"); 98 if ((strOne != result.npos) && (strTwo != result.npos)) { 99 flag = true; 100 } 101 EXPECT_EQ(ret, true); 102 EXPECT_TRUE(flag); 103 } 104 105 /** 106 * @tc.name: FpsTestCase 107 * @tc.desc: Test FPS 108 * @tc.type: FUNC 109 */ 110 HWTEST_F(SPdaemonTest, FpsTestCase, TestSize.Level1) 111 { 112 FPS &fps = FPS::GetInstance(); 113 std::string packName = "ohos.samples.ecg"; 114 std::string surfaceViewName; 115 FpsInfo fpsInfoResult; 116 117 fps.SetFpsCurrentFpsTime(fpsInfoResult); 118 fps.SetPackageName(packName); 119 fps.SetLayerName(surfaceViewName); 120 fps.CalcFpsAndJitters(true); 121 122 std::string cmd = "SP_daemon -N 1 -PKG ohos.samples.ecg -f"; 123 std::string result = ""; 124 bool flag = false; 125 auto ret = SPUtils::LoadCmd(cmd, result); 126 std::string::size_type strOne = result.find("fpsJitters"); 127 std::string::size_type strTwo = result.find("timestamp"); 128 if ((strOne != result.npos) && (strTwo != result.npos)) { 129 flag = true; 130 } 131 EXPECT_EQ(ret, true); 132 EXPECT_TRUE(flag); 133 } 134 135 /** 136 * @tc.name: TemperatureTestCase 137 * @tc.desc: Test Temperature 138 * @tc.type: FUNC 139 */ 140 HWTEST_F(SPdaemonTest, TemperatureTestCase, TestSize.Level1) 141 { 142 std::string cmd = "SP_daemon -N 1 -t"; 143 std::string result = ""; 144 bool flag = false; 145 auto ret = SPUtils::LoadCmd(cmd, result); 146 std::string::size_type strOne = result.find("timestamp"); 147 std::string::size_type strTwo = result.find("system_h"); 148 std::string::size_type strThree = result.find("gpu-thermal"); 149 if ((strOne != result.npos) && ((strTwo != result.npos) || (strThree != result.npos))) { 150 flag = true; 151 } 152 EXPECT_EQ(ret, true); 153 EXPECT_TRUE(flag); 154 } 155 156 /** 157 * @tc.name: PowerTestCase 158 * @tc.desc: Test Power 159 * @tc.type: FUNC 160 */ 161 HWTEST_F(SPdaemonTest, PowerTestCase, TestSize.Level1) 162 { 163 std::string cmd = "SP_daemon -N 1 -p"; 164 std::string result = ""; 165 bool flag = false; 166 auto ret = SPUtils::LoadCmd(cmd, result); 167 std::string::size_type strOne = result.find("currentNow"); 168 std::string::size_type strTwo = result.find("voltageNow"); 169 std::string::size_type strThree = result.find("timestamp"); 170 if ((strOne != result.npos) && (strTwo != result.npos)) { 171 flag = true; 172 } else if ((strThree != result.npos)) { 173 flag = true; 174 } 175 EXPECT_EQ(ret, true); 176 EXPECT_TRUE(flag); 177 } 178 179 /** 180 * @tc.name: RamTestCase 181 * @tc.desc: Test RAM 182 * @tc.type: FUNC 183 */ 184 HWTEST_F(SPdaemonTest, RamTestCase, TestSize.Level1) 185 { 186 RAM &ram = RAM::GetInstance(); 187 std::string packName = "ohos.samples.ecg"; 188 189 ram.SetFirstFlag(); 190 ram.SetPackageName(packName); 191 ram.ThreadGetPss(); 192 ram.TriggerGetPss(); 193 194 std::string cmd = "SP_daemon -N 1 -PKG ohos.samples.ecg -r"; 195 std::string result = ""; 196 bool flag = false; 197 auto ret = SPUtils::LoadCmd(cmd, result); 198 std::string::size_type strOne = result.find("memAvailable"); 199 std::string::size_type strTwo = result.find("memTotal"); 200 if ((strOne != result.npos) && (strTwo != result.npos)) { 201 flag = true; 202 } 203 EXPECT_EQ(ret, true); 204 EXPECT_TRUE(flag); 205 } 206 207 /** 208 * @tc.name: NetWorkTestCase 209 * @tc.desc: Test NetWork 210 * @tc.type: FUNC 211 */ 212 HWTEST_F(SPdaemonTest, NetWorkTestCase, TestSize.Level1) 213 { 214 std::string cmd = "SP_daemon -N 1 -net"; 215 std::string result = ""; 216 bool flag = false; 217 auto ret = SPUtils::LoadCmd(cmd, result); 218 std::string::size_type strOne = result.find("networkDown"); 219 std::string::size_type strTwo = result.find("networkUp"); 220 if ((strOne != result.npos) && (strTwo != result.npos)) { 221 flag = true; 222 } 223 EXPECT_EQ(ret, true); 224 EXPECT_TRUE(flag); 225 } 226 227 /** 228 * @tc.name: StartTestCase 229 * @tc.desc: Test Start 230 * @tc.type: FUNC 231 */ 232 HWTEST_F(SPdaemonTest, StartTestCase, TestSize.Level1) 233 { 234 std::string cmd = "SP_daemon -start -g"; 235 std::string result = ""; 236 bool flag = false; 237 auto ret = SPUtils::LoadCmd(cmd, result); 238 std::string::size_type strOne = result.find("Collection"); 239 std::string::size_type strTwo = result.find("begins"); 240 if ((strOne != result.npos) && (strTwo != result.npos)) { 241 flag = true; 242 } 243 EXPECT_EQ(ret, true); 244 EXPECT_TRUE(flag); 245 } 246 247 /** 248 * @tc.name: StopTestCase 249 * @tc.desc: Test Stop 250 * @tc.type: FUNC 251 */ 252 HWTEST_F(SPdaemonTest, StopTestCase, TestSize.Level1) 253 { 254 std::string cmd = "SP_daemon -stop"; 255 std::string result = ""; 256 bool flag = false; 257 auto ret = SPUtils::LoadCmd(cmd, result); 258 std::string::size_type strOne = result.find("Collection"); 259 std::string::size_type strTwo = result.find("ended"); 260 if ((strOne != result.npos) && (strTwo != result.npos)) { 261 flag = true; 262 } 263 EXPECT_EQ(ret, true); 264 EXPECT_TRUE(flag); 265 } 266 267 /** 268 * @tc.name: ScreenTestCase 269 * @tc.desc: Test Screen 270 * @tc.type: FUNC 271 */ 272 HWTEST_F(SPdaemonTest, ScreenTestCase, TestSize.Level1) 273 { 274 std::string cmd = "SP_daemon -screen"; 275 std::string result = ""; 276 bool flag = false; 277 auto ret = SPUtils::LoadCmd(cmd, result); 278 std::string::size_type strOne = result.find("activeMode"); 279 std::string::size_type strTwo = result.find("refreshrate"); 280 if ((strOne != result.npos) && (strTwo != result.npos)) { 281 flag = true; 282 } 283 EXPECT_EQ(ret, true); 284 EXPECT_TRUE(flag); 285 } 286 287 /** 288 * @tc.name: FrameLossTestCase 289 * @tc.desc: Test FrameLoss 290 * @tc.type: FUNC 291 */ 292 HWTEST_F(SPdaemonTest, FrameLossTestCase, TestSize.Level1) 293 { 294 std::string cmd = "SP_daemon -editor frameLoss"; 295 std::string result = ""; 296 bool flag = false; 297 auto ret = SPUtils::LoadCmd(cmd, result); 298 std::string::size_type strOne = result.find("BUNDLE_NAME"); 299 std::string::size_type strTwo = result.find("TOTAL_APP_MISSED_FRAMES"); 300 if ((strOne != result.npos) && (strTwo != result.npos)) { 301 flag = true; 302 } 303 EXPECT_EQ(ret, true); 304 EXPECT_TRUE(flag); 305 } 306 307 /** 308 * @tc.name: DdrTestCase 309 * @tc.desc: Test DDR 310 * @tc.type: FUNC 311 */ 312 HWTEST_F(SPdaemonTest, DdrTestCase, TestSize.Level1) 313 { 314 std::string cmd = "SP_daemon -N 1 -d"; 315 std::string result = ""; 316 bool flag = false; 317 auto ret = SPUtils::LoadCmd(cmd, result); 318 DDR &ddr = DDR::GetInstance(); 319 ddr.SetRkFlag(); 320 ddr.GetDdrFreq(); 321 std::string::size_type strOne = result.find("ddrFrequency"); 322 if (strOne != result.npos) { 323 flag = true; 324 } 325 EXPECT_EQ(ret, true); 326 EXPECT_TRUE(flag); 327 } 328 329 /** 330 * @tc.name: Navigation 331 * @tc.desc: Test Navigation 332 * @tc.type: FUNC 333 */ 334 HWTEST_F(SPdaemonTest, Navigation, TestSize.Level1) 335 { 336 Navigation &nav = Navigation::GetInstance(); 337 std::string packName = "ohos.samples.ecg"; 338 339 std::map<std::string, std::string> navItemData = nav.ItemData(); 340 341 std::string cmd = "SP_daemon -N 1 -PKG ohos.samples.ecg -nav"; 342 std::string result = ""; 343 bool flag = false; 344 auto ret = SPUtils::LoadCmd(cmd, result); 345 std::string::size_type strOne = result.find("navPathName"); 346 std::string::size_type strTwo = result.find("No Navigation Info"); 347 if ((strOne != result.npos) && (strTwo != result.npos)) { 348 flag = true; 349 } 350 EXPECT_EQ(ret, true); 351 EXPECT_TRUE(flag); 352 } 353 } // namespace OHOS 354 } // namespace SmartPerf