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