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 * @tc.name: SADumperTest008
126 * @tc.desc: Test SA MultimodalInput result contain "Windows".
127 * @tc.type: FUNC
128 * @tc.require: issueI5NWZQ
129 */
130 HWTEST_F(SADumperTest, SADumperTest008, TestSize.Level3)
131 {
132 std::string cmd = "hidumper -s MultimodalInput -a -w";
133 std::string str = "Windows";
134 ASSERT_TRUE(HidumperTestUtils::GetInstance().IsExistInCmdResult(cmd, str));
135 }
136
137 /**
138 * @tc.name: SADumperTest009
139 * @tc.desc: Test SA RenderService result contain "Graphic".
140 * @tc.type: FUNC
141 * @tc.require: issueI5NWZQ
142 */
143 HWTEST_F(SADumperTest, SADumperTest009, TestSize.Level3)
144 {
145 std::string path = "/data/log/hidumper/RenderService.txt";
146 std::string cmd = "hidumper -s 10 -a -h > " + path;
147 std::string str = "Graphic";
148 ASSERT_TRUE(HidumperTestUtils::GetInstance().IsExistStrInFile(cmd, str, path));
149 system("rm -rf /data/log/hidumper/RenderService.txt");
150 }
151
152 /**
153 * @tc.name: SADumperTest010
154 * @tc.desc: Test zip SA RenderService result not contain "Graphic".
155 * @tc.type: FUNC
156 * @tc.require: issueI5NWZQ
157 */
158 HWTEST_F(SADumperTest, SADumperTest010, TestSize.Level3)
159 {
160 std::string cmd = "hidumper -s 10 -a -h --zip";
161 std::string str = "Graphic";
162 ASSERT_FALSE(HidumperTestUtils::GetInstance().IsExistInCmdResult(cmd, str));
163 }
164
165 /**
166 * @tc.name: SADumperTest011
167 * @tc.desc: Test SA AbilityManagerService result contain "AppRunningRecord".
168 * @tc.type: FUNC
169 * @tc.require: issueI5NWZQ
170 */
171 HWTEST_F(SADumperTest, SADumperTest011, TestSize.Level3)
172 {
173 std::string cmd = "hidumper -s AbilityManagerService -a '-a'";
174 std::string str = "AppRunningRecord";
175 ASSERT_TRUE(HidumperTestUtils::GetInstance().IsExistInCmdResult(cmd, str));
176 }
177
178 /**
179 * @tc.name: SADumperTest012
180 * @tc.desc: Test mutilthread for class member variable.
181 * @tc.type: FUNC
182 */
183 HWTEST_F(SADumperTest, SADumperTest012, TestSize.Level3)
184 {
185 for (int i = 0; i < THREAD_EXECUTE_NUM; i++) {
__anon73f7a5230102() 186 std::thread([&]() mutable {
187 std::string cmd = "hidumper --cpuusage 1";
188 std::string str = "Pss";
189 ASSERT_TRUE(HidumperTestUtils::GetInstance().IsExistInCmdResult(cmd, str));
190 }).detach();
__anon73f7a5230202() 191 std::thread([&]() mutable {
192 std::string cmd = "hidumper -s 1201";
193 std::string str = "Plugins";
194 ASSERT_TRUE(HidumperTestUtils::GetInstance().IsExistInCmdResult(cmd, str));
195 }).detach();
196 }
197 }
198 } // namespace HiviewDFX
199 } // namespace OHOS