• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024 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 #include <gtest/gtest.h>
16 #include <thread>
17 #include <unistd.h>
18 #include "hidumper_test_utils.h"
19 
20 using namespace testing::ext;
21 namespace OHOS {
22 namespace HiviewDFX {
23 const int THREAD_EXECUTE_NUM = 2;
24 class SADumperTest : public testing::Test {
25 public:
26     static void SetUpTestCase(void);
27     static void TearDownTestCase(void);
28     void SetUp();
29     void TearDown();
30 };
31 
SetUpTestCase(void)32 void SADumperTest::SetUpTestCase(void)
33 {
34 }
TearDownTestCase(void)35 void SADumperTest::TearDownTestCase(void)
36 {
37 }
SetUp(void)38 void SADumperTest::SetUp(void)
39 {
40 }
TearDown(void)41 void SADumperTest::TearDown(void)
42 {
43 }
44 
45 /**
46  * @tc.name: SADumperTest001
47  * @tc.desc: Test SA HiviewService result contain "log".
48  * @tc.type: FUNC
49  * @tc.require: issueI5NWZQ
50  */
51 #ifdef HIDUMPER_HIVIEWDFX_HIVIEW_ENABLE
52 HWTEST_F(SADumperTest, SADumperTest001, TestSize.Level3)
53 {
54     std::string cmd = "hidumper -s 1201 -a '-p Faultlogger'";
55     std::string str = "log";
56     ASSERT_TRUE(HidumperTestUtils::GetInstance().IsExistInCmdResult(cmd, str));
57 }
58 #endif
59 
60 /**
61  * @tc.name: SADumperTest002
62  * @tc.desc: Test SA WindowManagerService result contain "WindowName".
63  * @tc.type: FUNC
64  * @tc.require: issueI5NX04
65  */
66 HWTEST_F(SADumperTest, SADumperTest002, TestSize.Level3)
67 {
68     std::string cmd = "hidumper -s WindowManagerService -a -a";
69     std::string str = "WindowName";
70     ASSERT_TRUE(HidumperTestUtils::GetInstance().IsExistInCmdResult(cmd, str));
71 }
72 
73 /**
74  * @tc.name: SADumperTest003
75  * @tc.desc: Test SA RenderService result contain "ScreenInfo".
76  * @tc.type: FUNC
77  * @tc.require: issueI5NWZQ
78  */
79 HWTEST_F(SADumperTest, SADumperTest003, TestSize.Level3)
80 {
81     std::string cmd = "hidumper -s 10 -a allInfo";
82     std::string str = "ScreenInfo";
83     ASSERT_TRUE(HidumperTestUtils::GetInstance().IsExistInCmdResult(cmd, str));
84 }
85 
86 /**
87  * @tc.name: SADumperTest004
88  * @tc.desc: Test SA WorkSchedule result contain "Work".
89  * @tc.type: FUNC
90  * @tc.require: issueI5NWZQ
91  */
92 HWTEST_F(SADumperTest, SADumperTest004, TestSize.Level3)
93 {
94     std::string cmd = "hidumper -s 1904 -a -a";
95     std::string str = "Work";
96     ASSERT_TRUE(HidumperTestUtils::GetInstance().IsExistInCmdResult(cmd, str));
97 }
98 /**
99  * @tc.name: SADumperTest005
100  * @tc.desc: Test SA AbilityManagerService result contain "User".
101  * @tc.type: FUNC
102  * @tc.require: issueI5NWZQ
103  */
104 HWTEST_F(SADumperTest, SADumperTest005, TestSize.Level3)
105 {
106     std::string cmd = "hidumper -s AbilityManagerService -a -l";
107     std::string str = "User";
108     ASSERT_TRUE(HidumperTestUtils::GetInstance().IsExistInCmdResult(cmd, str));
109 }
110 
111 /**
112  * @tc.name: SADumperTest006
113  * @tc.desc: Test SA DisplayManagerService result contain "Screen".
114  * @tc.type: FUNC
115  * @tc.require: issueI5NWZQ
116  */
117 HWTEST_F(SADumperTest, SADumperTest006, TestSize.Level3)
118 {
119     std::string cmd = "hidumper -s DisplayManagerService -a '-s -a'";
120     std::string str = "Screen";
121     ASSERT_TRUE(HidumperTestUtils::GetInstance().IsExistInCmdResult(cmd, str));
122 }
123 
124 
125 /**
126  * @tc.name: SADumperTest009
127  * @tc.desc: Test SA RenderService result contain "Graphic".
128  * @tc.type: FUNC
129  * @tc.require: issueI5NWZQ
130  */
131 HWTEST_F(SADumperTest, SADumperTest007, TestSize.Level3)
132 {
133     std::string path = "/data/log/hidumper/RenderService.txt";
134     std::string cmd = "hidumper -s 10 -a -h > " + path;
135     std::string str = "Graphic";
136     ASSERT_TRUE(HidumperTestUtils::GetInstance().IsExistStrInFile(cmd, str, path));
137     system("rm -rf /data/log/hidumper/RenderService.txt");
138 }
139 
140 /**
141  * @tc.name: SADumperTest010
142  * @tc.desc: Test zip SA RenderService result not contain "Graphic".
143  * @tc.type: FUNC
144  * @tc.require: issueI5NWZQ
145  */
146 HWTEST_F(SADumperTest, SADumperTest008, TestSize.Level3)
147 {
148     std::string cmd = "hidumper -s 10 -a -h --zip";
149     std::string str = "Graphic";
150     ASSERT_FALSE(HidumperTestUtils::GetInstance().IsExistInCmdResult(cmd, str));
151 }
152 
153 /**
154  * @tc.name: SADumperTest011
155  * @tc.desc: Test SA AbilityManagerService result contain "AppRunningRecord".
156  * @tc.type: FUNC
157  * @tc.require: issueI5NWZQ
158  */
159 HWTEST_F(SADumperTest, SADumperTest009, TestSize.Level3)
160 {
161     std::string cmd = "hidumper -s AbilityManagerService -a '-a'";
162     std::string str = "AppRunningRecord";
163     ASSERT_TRUE(HidumperTestUtils::GetInstance().IsExistInCmdResult(cmd, str));
164 }
165 
166 /**
167  * @tc.name: SADumperTest012
168  * @tc.desc: Test mutilthread for class member variable.
169  * @tc.type: FUNC
170  */
171 HWTEST_F(SADumperTest, SADumperTest010, TestSize.Level3)
172 {
173     for (int i = 0; i < THREAD_EXECUTE_NUM; i++) {
__anondf9d01c50102() 174         std::thread([&]() mutable {
175             std::string cmd = "hidumper --cpuusage 1";
176             std::string str = "Pss";
177             ASSERT_TRUE(HidumperTestUtils::GetInstance().IsExistInCmdResult(cmd, str));
178         }).detach();
__anondf9d01c50202() 179         std::thread([&]() mutable {
180             std::string cmd = "hidumper -s 1201";
181             std::string str = "Plugins";
182             ASSERT_TRUE(HidumperTestUtils::GetInstance().IsExistInCmdResult(cmd, str));
183         }).detach();
184     }
185 }
186 } // namespace HiviewDFX
187 } // namespace OHOS