1 /*
2 * Copyright (c) 2023 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 <gtest/gtest.h>
17 #include <string>
18 #include <thread>
19 #include <fstream>
20 #include <fcntl.h>
21 #include <sys/prctl.h>
22 #include <unistd.h>
23 #include <dlfcn.h>
24 #include <chrono>
25 #include <cstdio>
26 #include "watchdog_inner_test.h"
27
28 #define private public
29 #define protected public
30 #include "watchdog_inner.h"
31 #undef private
32 #undef protected
33
34 #include "xcollie_define.h"
35 #include "xcollie_utils.h"
36 #include "directory_ex.h"
37 #include "file_ex.h"
38 #include "event_handler.h"
39 #include "ffrt_inner.h"
40 #include "parameters.h"
41 #include "watchdog_inner_util_test.h"
42
43 using namespace testing::ext;
44 using namespace OHOS::AppExecFwk;
45 namespace OHOS {
46 namespace HiviewDFX {
SetUpTestCase(void)47 void WatchdogInnerTest::SetUpTestCase(void)
48 {
49 }
50
TearDownTestCase(void)51 void WatchdogInnerTest::TearDownTestCase(void)
52 {
53 }
54
SetUp(void)55 void WatchdogInnerTest::SetUp(void)
56 {
57 InitSeLinuxEnabled();
58 }
59
TearDown(void)60 void WatchdogInnerTest::TearDown(void)
61 {
62 CancelSeLinuxEnabled();
63 }
64
InitBeginFuncTest(const char * name)65 static void InitBeginFuncTest(const char* name)
66 {
67 std::string nameStr(name);
68 }
69
InitEndFuncTest(const char * name)70 static void InitEndFuncTest(const char* name)
71 {
72 std::string nameStr(name);
73 }
74
TestCreateFile(const std::string & path)75 int TestCreateFile(const std::string &path)
76 {
77 if (OHOS::FileExists(path)) {
78 return 0;
79 } else {
80 std::ofstream fout(path);
81 if (!fout.is_open()) {
82 return -1;
83 }
84 fout.flush();
85 fout.close();
86 chmod(path.c_str(), 0644); // 0644: test value
87 }
88 return 0;
89 }
90
TestInitAppStartSample(AppStartContent & startContent)91 void TestInitAppStartSample(AppStartContent& startContent)
92 {
93 startContent.threshold = 500; // 500: test value
94 startContent.sampleInterval = 50; // 50: test value
95 startContent.targetCount = 10; // 10: test value
96 startContent.reportTimes = 1; // 1: test value
97 startContent.startTime = GetTimeStamp();
98 startContent.enableStartSample = true;
99 startContent.startUpDuration = 5000; // 5000: test value
100 }
101
102 /**
103 * @tc.name: WatchdogInner TriggerTimerCountTask Test
104 * @tc.desc: add teatcase
105 * @tc.type: FUNC
106 */
107 HWTEST_F(WatchdogInnerTest, WatchdogInnerTest_TriggerTimerCountTask_001, TestSize.Level1)
108 {
109 std::string name = "WatchdogInnerTest_RunPeriodicalTask_001";
110 WatchdogInner::GetInstance().TriggerTimerCountTask(name, true, "test");
111 ASSERT_EQ(WatchdogInner::GetInstance().checkerQueue_.size(), 0);
112 }
113
114 /**
115 * @tc.name: WatchdogInner is exceedMaxTaskLocked;
116 * @tc.desc: Verify whether checkerQueue_ is over MAX_WATCH_NUM;
117 * @tc.type: FUNC
118 */
119 HWTEST_F(WatchdogInnerTest, WatchdogInnerTest_IsExceedMaxTaskLocked_001, TestSize.Level1)
120 {
121 bool ret = WatchdogInner::GetInstance().IsExceedMaxTaskLocked();
122 ASSERT_EQ(ret, false);
123 }
124
125 /**
126 * @tc.name: WatchdogInner FfrtCallback Test;
127 * @tc.desc: add teatcase
128 * @tc.type: FUNC
129 */
130 HWTEST_F(WatchdogInnerTest, WatchdogInnerTest_FfrtCallback_001, TestSize.Level1)
131 {
132 uint64_t taskId = 1;
133 const char *taskInfo = "task";
134 uint32_t delayedTaskCount = 0;
135 ASSERT_TRUE(WatchdogInner::GetInstance().taskIdCnt.empty());
136 WatchdogInner::GetInstance().FfrtCallback(taskId, taskInfo, delayedTaskCount);
137 }
138
139 /**
140 * @tc.name: WatchdogInner FfrtCallback Test;
141 * @tc.desc: add teatcase
142 * @tc.type: FUNC
143 */
144 HWTEST_F(WatchdogInnerTest, WatchdogInnerTest_FfrtCallback_002, TestSize.Level1)
145 {
146 uint64_t taskId = 1;
147 const char *taskInfo = "Queue_Schedule_Timeout";
148 uint32_t delayedTaskCount = 0;
149 OHOS::system::SetParameter("hiviewdfx.appfreeze.filter_bundle_name", "WatchdogInnerUnitTest");
150 EXPECT_TRUE(IsProcessDebug(getprocpid()));
151 WatchdogInner::GetInstance().FfrtCallback(taskId, taskInfo, delayedTaskCount);
152 }
153
154 /**
155 * @tc.name: WatchdogInner SendMsgToHungtask Test;
156 * @tc.desc: add teatcase
157 * @tc.type: FUNC
158 */
159 HWTEST_F(WatchdogInnerTest, WatchdogInnerTest_SendMsgToHungtask_001, TestSize.Level1)
160 {
161 bool ret =WatchdogInner::GetInstance().SendMsgToHungtask(
162 "WatchdogInnerTest_SendMsgToHungtask_001");
163 ASSERT_FALSE(ret);
164 }
165
166 /**
167 * @tc.name: WatchdogInner
168 * @tc.desc: add testcase
169 * @tc.type: FUNC
170 */
171 HWTEST_F(WatchdogInnerTest, WatchdogInnerTest_KillProcessTest, TestSize.Level1)
172 {
173 int32_t pid = 12000; // test value
174 bool ret = KillProcessByPid(pid);
175 EXPECT_EQ(ret, false);
176 ret = IsProcessDebug(pid);
177 printf("IsProcessDebug ret=%s", ret ? "true" : "false");
178 std::string path = "/data/test/log/test1.txt";
179 std::ofstream ofs(path, std::ios::trunc);
180 if (!ofs.is_open()) {
181 printf("open path failed!, path=%s\n", path.c_str());
182 FAIL();
183 }
184 ofs << "aync 1:1 to 2:2 code 9 wait:4 s test" << std::endl;
185 ofs << "12000:12000 to 12001:12001 code 9 wait:1 s test" << std::endl;
186 ofs << "22000:22000 to 12001:12001 code 9 wait:1 s test" << std::endl;
187 ofs << "12000:12000 to 12001:12001 code 9 wait:4 s test" << std::endl;
188 ofs.close();
189 std::ifstream fin(path);
190 if (!fin.is_open()) {
191 printf("open path failed!, path=%s\n", path.c_str());
192 FAIL();
193 }
194 int result = ParsePeerBinderPid(fin, pid);
195 fin.close();
196 EXPECT_TRUE(result > 0);
197
198 path = "/data/test/log/test2.txt";
199 ofs.open(path.c_str(), std::ios::trunc);
200 if (!ofs.is_open()) {
201 printf("open path failed!, path=%s\n", path.c_str());
202 FAIL();
203 }
204 ofs << "context" << std::endl;
205 ofs.close();
206 fin.open(path.c_str());
207 if (!fin.is_open()) {
208 printf("open path failed!, path=%s\n", path.c_str());
209 FAIL();
210 }
211 result = ParsePeerBinderPid(fin, pid);
212 fin.close();
213 EXPECT_TRUE(result < 0);
214 }
215
216 /**
217 * @tc.name: WatchdogInner;
218 * @tc.desc: add testcase
219 * @tc.type: FUNC
220 */
221 HWTEST_F(WatchdogInnerTest, WatchdogInnerTest_001, TestSize.Level1)
222 {
223 std::string result = GetFormatDate();
224 printf("GetFormatDate:%s\n", result.c_str());
225 EXPECT_TRUE(!result.empty());
226 bool devRet1 = IsDeveloperOpen();
227 bool devRet2 = IsDeveloperOpen();
228 bool betaRet1 = IsBetaVersion();
229 bool betaRet2 = IsBetaVersion();
230 EXPECT_TRUE(devRet1 == devRet2);
231 EXPECT_TRUE(betaRet1 == betaRet2);
232 int64_t ret1 = GetTimeStamp();
233 EXPECT_TRUE(ret1 > 0);
234 std::string stack = "";
235 std::string heaviestStack = "";
236 const char* samplePath = "libthread_sampler.z.so";
237 WatchdogInner::GetInstance().threadSamplerFuncHandler_ = dlopen(samplePath, RTLD_LAZY);
238 EXPECT_TRUE(WatchdogInner::GetInstance().threadSamplerFuncHandler_ != nullptr);
239 WatchdogInner::GetInstance().InitThreadSamplerFuncs();
240 WatchdogInner::GetInstance().CollectStack(stack, heaviestStack);
241 printf("stack:\n%s", stack.c_str());
242 printf("heaviestStack:\n%s", heaviestStack.c_str());
243 WatchdogInner::GetInstance().Deinit();
244 WatchdogInner::GetInstance().ResetThreadSamplerFuncs();
245 }
246
247 /**
248 * @tc.name: WatchdogInner;
249 * @tc.desc: add testcase
250 * @tc.type: FUNC
251 */
252 HWTEST_F(WatchdogInnerTest, WatchdogInnerTest_002, TestSize.Level1)
253 {
254 TimePoint endTime = std::chrono::steady_clock::now();
255 int sampleInterval = SAMPLE_DEFULE_INTERVAL;
256 WatchdogInner::GetInstance().StartProfileMainThread(endTime, 150, sampleInterval);
257 int32_t left = 4;
258 int32_t end = time(nullptr) + left;
259 while (left > 0) {
260 left = end - time(nullptr);
261 }
262
263 left = 10;
264 end = time(nullptr) + left;
265 while (left > 0) {
266 left = end - time(nullptr);
267 }
268
269 WatchdogInner::GetInstance().StartProfileMainThread(endTime, 150, sampleInterval);
270 left = 5;
271 end = time(nullptr) + left;
272 while (left > 0) {
273 left = end - time(nullptr);
274 }
275 sleep(4);
276 std::string stack = "";
277 std::string heaviestStack = "";
278 WatchdogInner::GetInstance().CollectStack(stack, heaviestStack);
279 printf("stack:\n%s", stack.c_str());
280 printf("heaviestStack:\n%s", heaviestStack.c_str());
281 WatchdogInner::GetInstance().Deinit();
282 WatchdogInner::GetInstance().ResetThreadSamplerFuncs();
283 EXPECT_TRUE(stack.size() >= heaviestStack.size());
284 }
285
286
287 /**
288 * @tc.name: WatchdogInner;
289 * @tc.desc: add testcase
290 * @tc.type: FUNC
291 */
292 HWTEST_F(WatchdogInnerTest, WatchdogInnerTest_003, TestSize.Level1)
293 {
__anoncafa5dc20102(const std::string &name, int waitState) 294 auto timeOutCallback = [](const std::string &name, int waitState) {
295 printf("timeOutCallback name is %s, waitState is %d\n", name.c_str(), waitState);
296 };
297 int result = WatchdogInner::GetInstance().AddThread("AddThread", nullptr, timeOutCallback, 10);
298 EXPECT_TRUE(result <= 0);
299 int32_t pid = getprocpid();
300 bool writeResult = WatchdogInner::WriteStringToFile(pid, "0");
301 EXPECT_TRUE(!writeResult);
302 std::string eventName = WatchdogInner::GetInstance().buissnessThreadInfo_.empty() ?
303 "MAIN_THREAD_JANK" : "BUSSINESS_THREAD_JANK";
304 bool ret = WatchdogInner::GetInstance().ReportMainThreadEvent(gettid(), eventName);
305 printf("ReportMainThreadEvent ret=%s\n", ret ? "true" : "fasle");
306 ret = WatchdogInner::GetInstance().ReportMainThreadEvent(gettid(), eventName, true, true);
307 printf("ReportMainThreadEvent ret=%s\n", ret ? "true" : "fasle");
308 ret = WatchdogInner::GetInstance().ReportMainThreadEvent(gettid(), eventName, false, true);
309 printf("ReportMainThreadEvent ret=%s\n", ret ? "true" : "fasle");
310 int32_t interval = 150; // test value
311 WatchdogInner::GetInstance().StartTraceProfile();
312 WatchdogInner::GetInstance().DumpTraceProfile(interval);
313 ret = IsFileNameFormat('1');
314 EXPECT_TRUE(!ret);
315 ret = IsFileNameFormat('b');
316 EXPECT_TRUE(!ret);
317 ret = IsFileNameFormat('B');
318 EXPECT_TRUE(!ret);
319 ret = IsFileNameFormat('_');
320 EXPECT_TRUE(!ret);
321 ret = IsFileNameFormat('*');
322 EXPECT_TRUE(ret);
323 std::string path = "";
324 std::string stack = "STACK";
325 bool isOverLimit = false;
326 ret = WriteStackToFd(getprocpid(), path, stack, "test", isOverLimit);
327 EXPECT_TRUE(ret);
328 }
329
330 /**
331 * @tc.name: WatchdogInner Test
332 * @tc.desc: add testcase
333 * @tc.type: FUNC
334 */
335 HWTEST_F(WatchdogInnerTest, WatchdogInnerTest_004, TestSize.Level1)
336 {
337 WatchdogInner::GetInstance().buissnessThreadInfo_.insert(getproctid());
338 EXPECT_TRUE(WatchdogInner::GetInstance().buissnessThreadInfo_.size() > 0);
339 printf("ret=%d\n", WatchdogInner::GetInstance().ReportMainThreadEvent(gettid(),
340 "BUSSINESS_THREAD_JANK"));
341 WatchdogInner::GetInstance().StartTraceProfile();
342 WatchdogInner::GetInstance().DumpTraceProfile(150); // test value
343 FunctionOpen(nullptr, "test");
344 }
345
346 /**
347 * @tc.name: WatchdogInner GetFfrtTaskTid test;
348 * @tc.desc: add testcase
349 * @tc.type: FUNC
350 */
351 HWTEST_F(WatchdogInnerTest, WatchdogInnerTest_GetFfrtTaskTid_001, TestSize.Level1)
352 {
353 std::string msg = "us. queue name";
354 std::string str = "us. queue name [";
355 auto index = msg.find(str);
356 EXPECT_TRUE(index == std::string::npos);
357 int32_t tid = -1;
358 WatchdogInner::GetInstance().GetFfrtTaskTid(tid, msg);
359 EXPECT_EQ(tid, -1);
360 }
361
362 /**
363 * @tc.name: WatchdogInner GetFfrtTaskTid test;
364 * @tc.desc: add testcase
365 * @tc.type: FUNC
366 */
367 HWTEST_F(WatchdogInnerTest, WatchdogInnerTest_GetFfrtTaskTid_002, TestSize.Level1)
368 {
369 std::string msg = "us. queue name []";
370 std::string str = "], remaining tasks count=";
371 auto index = msg.find(str);
372 EXPECT_TRUE(index == std::string::npos);
373 int32_t tid = -1;
374 WatchdogInner::GetInstance().GetFfrtTaskTid(tid, msg);
375 EXPECT_EQ(tid, -1);
376 }
377
378 /**
379 * @tc.name: WatchdogInner GetFfrtTaskTid test;
380 * @tc.desc: add testcase
381 * @tc.type: FUNC
382 */
383 HWTEST_F(WatchdogInnerTest, WatchdogInnerTest_GetFfrtTaskTid_003, TestSize.Level1)
384 {
385 std::string msg = "us. queue name [], remaining tasks count=11, worker tid "
386 "12220 is running, task id 12221";
387 std::string str = "], remaining tasks count=";
388 auto index = msg.find(str);
389 EXPECT_TRUE(index != std::string::npos);
390 int32_t tid = -1;
391 WatchdogInner::GetInstance().GetFfrtTaskTid(tid, msg);
392 EXPECT_EQ(tid, -1);
393 }
394
395 /**
396 * @tc.name: WatchdogInner GetFfrtTaskTid test;
397 * @tc.desc: add testcase
398 * @tc.type: FUNC
399 */
400 HWTEST_F(WatchdogInnerTest, WatchdogInnerTest_GetFfrtTaskTid_004, TestSize.Level1)
401 {
402 std::string msg = "us. queue name [WatchdogInnerTest_GetFfrtTaskTid_004], "
403 "remaining tasks count=11, worker tid abc\\nWatchdogInnerTest_GetFfrtTaskTid_004 "
404 " is running, task id 12221";
405 std::string str = "], remaining tasks count=";
406 auto index = msg.find(str);
407 EXPECT_TRUE(index != std::string::npos);
408 int32_t tid = -1;
409 WatchdogInner::GetInstance().GetFfrtTaskTid(tid, msg);
410 EXPECT_EQ(tid, -1);
411 }
412
413 /**
414 * @tc.name: WatchdogInner GetProcessNameFromProcCmdline test;
415 * @tc.desc: add testcase
416 * @tc.type: FUNC
417 */
418 HWTEST_F(WatchdogInnerTest, WatchdogInnerTest_GetProcNameFromProcCmdline_001, TestSize.Level1)
419 {
420 std::string procName1 = GetProcessNameFromProcCmdline(getpid());
421 std::string procName2 = GetProcessNameFromProcCmdline(25221); // test value
422 EXPECT_TRUE(procName1 != procName2);
423 std::string procName3 = GetProcessNameFromProcCmdline(getpid());
424 EXPECT_TRUE(procName1 == procName3);
425 }
426
427 /**
428 * @tc.name: WatchdogInner SendFfrtEvent test;
429 * @tc.desc: add testcase
430 * @tc.type: FUNC
431 */
432 HWTEST_F(WatchdogInnerTest, WatchdogInnerTest_SendFfrtEvent_001, TestSize.Level1)
433 {
434 EXPECT_TRUE(IsProcessDebug(getprocpid()));
435 std::string faultTimeStr = "\nFault time:" + FormatTime("%Y/%m/%d-%H:%M:%S") + "\n";
436 WatchdogInner::GetInstance().SendFfrtEvent("msg", "testName", "taskInfo", faultTimeStr);
437 }
438
439 /**
440 * @tc.name: WatchdogInner LeftTimeExitProcess test;
441 * @tc.desc: add testcase
442 * @tc.type: FUNC
443 */
444 HWTEST_F(WatchdogInnerTest, WatchdogInnerTest_LeftTimeExitProcess_001, TestSize.Level1)
445 {
446 EXPECT_TRUE(IsProcessDebug(getprocpid()));
447 WatchdogInner::GetInstance().LeftTimeExitProcess("msg");
448 }
449
450 /**
451 * @tc.name: WatchdogInner KillPeerBinderProcess test;
452 * @tc.desc: add testcase
453 * @tc.type: FUNC
454 */
455 HWTEST_F(WatchdogInnerTest, WatchdogInnerTest_KillPeerBinderProcess_001, TestSize.Level1)
456 {
457 EXPECT_TRUE(IsProcessDebug(getprocpid()));
458 WatchdogInner::GetInstance().KillPeerBinderProcess("msg");
459 }
460
461 /**
462 * @tc.name: WatchdogInner InitMainLooperWatcher Test
463 * @tc.desc: add testcase
464 * @tc.type: FUNC
465 */
466 HWTEST_F(WatchdogInnerTest, WatchdogInnerTest_InitMainLooperWatcher_001, TestSize.Level0)
467 {
468 WatchdogInner::GetInstance().InitMainLooperWatcher(nullptr, nullptr);
469 WatchdogInnerBeginFunc beginTest = InitBeginFuncTest;
470 WatchdogInnerEndFunc endTest = InitEndFuncTest;
471 WatchdogInner::GetInstance().InitMainLooperWatcher(&beginTest, &endTest);
472 int count = 0;
473 while (count < 40) {
474 beginTest("Test");
475 usleep(350 * 1000); // test value
476 endTest("Test");
477 count++;
478 }
479 WatchdogInner::GetInstance().traceContent_.traceState = 0;
480 WatchdogInner::GetInstance().InitMainLooperWatcher(&beginTest, &endTest);
481 beginTest("Test");
482 sleep(2); // test value
483 endTest("Test");
484 WatchdogInner::GetInstance().traceContent_.traceState = 1;
485 beginTest("Test");
486 usleep(3500 * 1000); // test value
487 endTest("Test");
488 EXPECT_TRUE(WatchdogInner::GetInstance().stackContent_.reportTimes < 1);
489 }
490
491 /**
492 * @tc.name: WatchdogInner InitMainLooperWatcher Test
493 * @tc.desc: add testcase
494 * @tc.type: FUNC
495 */
496 HWTEST_F(WatchdogInnerTest, WatchdogInnerTest_InitMainLooperWatcher_002, TestSize.Level0)
497 {
498 WatchdogInner::GetInstance().InitMainLooperWatcher(nullptr, nullptr);
499 WatchdogInnerBeginFunc beginTest = InitBeginFuncTest;
500 WatchdogInnerEndFunc endTest = InitEndFuncTest;
501 WatchdogInner::GetInstance().InitMainLooperWatcher(&beginTest, &endTest);
502 WatchdogInner::GetInstance().SetScrollState(true);
503 int count = 0;
504 while (count < 10) {
505 sleep(1); // test value
506 count++;
507 }
508 count = 0;
509 while (count < 4) {
510 beginTest("Test");
511 usleep(50 * 1000); // test value
512 endTest("Test");
513 count++;
514 }
515 sleep(2); // test value
516 EXPECT_EQ(WatchdogInner::GetInstance().isScroll_, true);
517 }
518
519 /**
520 * @tc.name: WatchdogInner SetEventConfig test;
521 * @tc.desc: set log_type failed.
522 * @tc.type: FUNC
523 */
524 HWTEST_F(WatchdogInnerTest, WatchdogInnerTest_SetEventConfig_001, TestSize.Level1)
525 {
526 /**
527 * @tc.name: WatchdogInner SetEventConfig test;
528 * @tc.desc: set paramsMap is null.
529 * @tc.type: FUNC
530 */
531 std::map<std::string, std::string> paramsMap;
532 int ret = WatchdogInner::GetInstance().SetEventConfig(paramsMap);
533 EXPECT_EQ(ret, -1);
534 /**
535 * @tc.name: WatchdogInner SetEventConfig test;
536 * @tc.desc: set log_type is not a number.
537 * @tc.type: FUNC
538 */
539 paramsMap[KEY_LOG_TYPE] = "";
540 ret = WatchdogInner::GetInstance().SetEventConfig(paramsMap);
541 EXPECT_EQ(ret, -1);
542 paramsMap[KEY_LOG_TYPE] = "ab0";
543 ret = WatchdogInner::GetInstance().SetEventConfig(paramsMap);
544 EXPECT_EQ(ret, -1);
545 /**
546 * @tc.name: WatchdogInner SetEventConfig test;
547 * @tc.desc: set log_type is negative number.
548 * @tc.type: FUNC
549 */
550 paramsMap[KEY_LOG_TYPE] = "-1";
551 ret = WatchdogInner::GetInstance().SetEventConfig(paramsMap);
552 EXPECT_EQ(ret, -1);
553 /**
554 * @tc.name: WatchdogInner SetEventConfig test;
555 * @tc.desc: set log_type success.
556 * @tc.type: FUNC
557 */
558 paramsMap[KEY_LOG_TYPE] = "0";
559 ret = WatchdogInner::GetInstance().SetEventConfig(paramsMap);
560 EXPECT_EQ(ret, 0);
561 /**
562 * @tc.name: WatchdogInner SetEventConfig test;
563 * @tc.desc: set log_type failed.
564 * @tc.type: FUNC
565 */
566 paramsMap[KEY_LOG_TYPE] = "1";
567 ret = WatchdogInner::GetInstance().SetEventConfig(paramsMap);
568 EXPECT_EQ(ret, -1);
569
570 /**
571 * @tc.name: WatchdogInner SetEventConfig test;
572 * @tc.desc: set log_type failed.
573 * @tc.type: FUNC
574 */
575 paramsMap[KEY_LOG_TYPE] = "2";
576 ret = WatchdogInner::GetInstance().SetEventConfig(paramsMap);
577 EXPECT_EQ(ret, 0);
578
579 /**
580 * @tc.name: WatchdogInner SetEventConfig test;
581 * @tc.desc: set log_type out of range.
582 * @tc.type: FUNC
583 */
584 paramsMap[KEY_LOG_TYPE] = "100";
585 ret = WatchdogInner::GetInstance().SetEventConfig(paramsMap);
586 EXPECT_EQ(ret, -1);
587 }
588
589 /**
590 * @tc.name: WatchdogInner SetEventConfig test;
591 * @tc.desc: set log_type is 1.
592 * @tc.type: FUNC
593 */
594 HWTEST_F(WatchdogInnerTest, WatchdogInnerTest_SetEventConfig_002, TestSize.Level1)
595 {
596 WatchdogInner::GetInstance().InitMainLooperWatcher(nullptr, nullptr);
597 WatchdogInnerBeginFunc beginTest = InitBeginFuncTest;
598 WatchdogInnerEndFunc endTest = InitEndFuncTest;
599 WatchdogInner::GetInstance().InitMainLooperWatcher(&beginTest, &endTest);
600
601 std::map<std::string, std::string> paramsMap;
602 paramsMap[KEY_LOG_TYPE] = "1";
603 paramsMap[KEY_SAMPLE_INTERVAL] = "100";
604 paramsMap[KEY_IGNORE_STARTUP_TIME] = "12";
605 paramsMap[KEY_SAMPLE_COUNT] = "21";
606 paramsMap[KEY_SAMPLE_REPORT_TIMES] = "3";
607 int ret = WatchdogInner::GetInstance().SetEventConfig(paramsMap);
608 EXPECT_EQ(ret, 0);
609 beginTest("Test");
610 sleep(12); // test value
611 int count = 0;
612 while (count < 3) {
613 beginTest("Test");
614 usleep(140 * 1000); // test value
615 endTest("Test");
616 count++;
617 }
618 sleep(5);
619 EXPECT_EQ(WatchdogInner::GetInstance().jankParamsMap[KEY_LOG_TYPE], 1);
620 EXPECT_EQ(WatchdogInner::GetInstance().jankParamsMap[KEY_SAMPLE_INTERVAL], 100);
621 EXPECT_EQ(WatchdogInner::GetInstance().jankParamsMap[KEY_IGNORE_STARTUP_TIME], 12);
622 EXPECT_EQ(WatchdogInner::GetInstance().jankParamsMap[KEY_SAMPLE_COUNT], 21);
623 EXPECT_TRUE(WatchdogInner::GetInstance().stackContent_.reportTimes < 3);
624 printf("stackContent_.reportTimes: %d", WatchdogInner::GetInstance().stackContent_.reportTimes);
625 }
626
627 /**
628 * @tc.name: WatchdogInner SetEventConfig test;
629 * @tc.desc: set log_type is 0.
630 * @tc.type: FUNC
631 */
632 HWTEST_F(WatchdogInnerTest, WatchdogInnerTest_SetEventConfig_003, TestSize.Level1)
633 {
634 WatchdogInner::GetInstance().InitMainLooperWatcher(nullptr, nullptr);
635 WatchdogInnerBeginFunc beginTest = InitBeginFuncTest;
636 WatchdogInnerEndFunc endTest = InitEndFuncTest;
637 WatchdogInner::GetInstance().InitMainLooperWatcher(&beginTest, &endTest);
638
639 std::map<std::string, std::string> paramsMap;
640 paramsMap[KEY_LOG_TYPE] = "0";
641 int ret = WatchdogInner::GetInstance().SetEventConfig(paramsMap);
642 EXPECT_EQ(ret, 0);
643 beginTest("Test");
644 sleep(11); // test value
645 int count = 0;
646 while (count < 2) {
647 beginTest("Test");
648 usleep(200 * 1000); // test value
649 endTest("Test");
650 count++;
651 }
652 sleep(5);
653 EXPECT_EQ(WatchdogInner::GetInstance().jankParamsMap[KEY_LOG_TYPE], 0);
654 EXPECT_EQ(WatchdogInner::GetInstance().jankParamsMap[KEY_SAMPLE_INTERVAL], SAMPLE_DEFULE_INTERVAL);
655 EXPECT_EQ(WatchdogInner::GetInstance().jankParamsMap[KEY_IGNORE_STARTUP_TIME], DEFAULT_IGNORE_STARTUP_TIME);
656 EXPECT_EQ(WatchdogInner::GetInstance().jankParamsMap[KEY_SAMPLE_COUNT], SAMPLE_DEFULE_COUNT);
657 printf("stackContent_.reportTimes: %d", WatchdogInner::GetInstance().stackContent_.reportTimes);
658 }
659
660 /**
661 * @tc.name: WatchdogInner SetEventConfig test;
662 * @tc.desc: set log_type is 2.
663 * @tc.type: FUNC
664 */
665 HWTEST_F(WatchdogInnerTest, WatchdogInnerTest_SetEventConfig_004, TestSize.Level1)
666 {
667 WatchdogInner::GetInstance().InitMainLooperWatcher(nullptr, nullptr);
668 WatchdogInnerBeginFunc beginTest = InitBeginFuncTest;
669 WatchdogInnerEndFunc endTest = InitEndFuncTest;
670 WatchdogInner::GetInstance().InitMainLooperWatcher(&beginTest, &endTest);
671
672 std::map<std::string, std::string> paramsMap;
673 paramsMap[KEY_LOG_TYPE] = "2";
674 int ret = WatchdogInner::GetInstance().SetEventConfig(paramsMap);
675 EXPECT_EQ(ret, 0);
676 beginTest("Test");
677 usleep(2000 * 1000); // test value
678 endTest("Test");
679 EXPECT_EQ(WatchdogInner::GetInstance().jankParamsMap[KEY_LOG_TYPE], 2);
680 EXPECT_EQ(WatchdogInner::GetInstance().jankParamsMap[KEY_SAMPLE_INTERVAL], SAMPLE_DEFULE_INTERVAL);
681 EXPECT_EQ(WatchdogInner::GetInstance().jankParamsMap[KEY_IGNORE_STARTUP_TIME], DEFAULT_IGNORE_STARTUP_TIME);
682 EXPECT_EQ(WatchdogInner::GetInstance().jankParamsMap[KEY_SAMPLE_COUNT], SAMPLE_DEFULE_COUNT);
683 }
684
685 /**
686 * @tc.name: WatchdogInner SetEventConfig test;
687 * @tc.desc: set KEY_LOG_TYPE is 1, other parameters out of range.
688 * @tc.type: FUNC
689 */
690 HWTEST_F(WatchdogInnerTest, WatchdogInnerTest_SetEventConfig_005, TestSize.Level1)
691 {
692 std::map<std::string, std::string> paramsMap;
693 /**
694 * @tc.desc: set sample interval out of range.
695 */
696 paramsMap[KEY_LOG_TYPE] = "1";
697 paramsMap[KEY_SAMPLE_INTERVAL] = "49";
698 paramsMap[KEY_IGNORE_STARTUP_TIME] = "15";
699 paramsMap[KEY_SAMPLE_COUNT] = "21";
700 paramsMap[KEY_SAMPLE_REPORT_TIMES] = "3";
701 int ret = WatchdogInner::GetInstance().SetEventConfig(paramsMap);
702 EXPECT_EQ(ret, -1);
703 /**
704 * @tc.desc: set ignore startup time out of range.
705 */
706 paramsMap[KEY_SAMPLE_INTERVAL] = "50";
707 paramsMap[KEY_IGNORE_STARTUP_TIME] = "1";
708 ret = WatchdogInner::GetInstance().SetEventConfig(paramsMap);
709 EXPECT_EQ(ret, -1);
710 /**
711 * @tc.desc: set sample count out of range.
712 */
713 paramsMap[KEY_IGNORE_STARTUP_TIME] = "10";
714 paramsMap[KEY_SAMPLE_COUNT] = "1000";
715 ret = WatchdogInner::GetInstance().SetEventConfig(paramsMap);
716 EXPECT_EQ(ret, -1);
717 /**
718 * @tc.desc: set report times out of range.
719 */
720 paramsMap[KEY_SAMPLE_COUNT] = "10";
721 paramsMap[KEY_SAMPLE_REPORT_TIMES] = "5";
722 ret = WatchdogInner::GetInstance().SetEventConfig(paramsMap);
723 EXPECT_EQ(ret, -1);
724 }
725
726 /**
727 * @tc.name: WatchdogInner SetEventConfig test;
728 * @tc.desc: set param is invalid.
729 * @tc.type: FUNC
730 */
731 HWTEST_F(WatchdogInnerTest, WatchdogInnerTest_SetEventConfig_006, TestSize.Level1)
732 {
733 std::map<std::string, std::string> paramsMap;
734 /**
735 * @tc.desc: set paramsMap's key is invalid.
736 */
737 paramsMap["ABC"] = "abc";
738 int ret = WatchdogInner::GetInstance().SetEventConfig(paramsMap);
739 EXPECT_EQ(ret, -1);
740 /**
741 * @tc.desc: set paramMap size out of range.
742 */
743 paramsMap[KEY_LOG_TYPE] = "0";
744 paramsMap[KEY_SAMPLE_INTERVAL] = "49";
745 ret = WatchdogInner::GetInstance().SetEventConfig(paramsMap);
746 EXPECT_EQ(ret, -1);
747 /**
748 * @tc.desc: set report times is not a number.
749 */
750 paramsMap[KEY_LOG_TYPE] = "1";
751 paramsMap[KEY_SAMPLE_INTERVAL] = "50";
752 paramsMap[KEY_IGNORE_STARTUP_TIME] = "15";
753 paramsMap[KEY_SAMPLE_COUNT] = "21";
754 paramsMap[KEY_SAMPLE_REPORT_TIMES] = "abc";
755 ret = WatchdogInner::GetInstance().SetEventConfig(paramsMap);
756 EXPECT_EQ(ret, -1);
757 /**
758 * @tc.desc: set sample count is not a number.
759 */
760 paramsMap[KEY_SAMPLE_COUNT] = "abc";
761 ret = WatchdogInner::GetInstance().SetEventConfig(paramsMap);
762 EXPECT_EQ(ret, -1);
763 /**
764 * @tc.desc: set ignore startup time out of range.
765 */
766 paramsMap[KEY_IGNORE_STARTUP_TIME] = "abc";
767 ret = WatchdogInner::GetInstance().SetEventConfig(paramsMap);
768 EXPECT_EQ(ret, -1);
769 /**
770 * @tc.desc: set sample interval out of range.
771 */
772 paramsMap[KEY_SAMPLE_INTERVAL] = "abc";
773 ret = WatchdogInner::GetInstance().SetEventConfig(paramsMap);
774 EXPECT_EQ(ret, -1);
775 }
776
777 /**
778 * @tc.name: WatchdogInner GetLimitedSizeName test;
779 * @tc.desc: add testcase
780 * @tc.type: FUNC
781 */
782 HWTEST_F(WatchdogInnerTest, WatchdogInnerTest_GetLimitedSizeName_001, TestSize.Level1)
783 {
784 std::string testStr = "WatchdogInnerTest_GetLimitedSizeName_001";
785 std::string name = testStr;
786 int limitValue = 128; // name limit value
787 while (name.size() <= limitValue) {
788 name += testStr;
789 }
790 EXPECT_TRUE(GetLimitedSizeName(name).size() <= limitValue);
791 }
792
793 /**
794 * @tc.name: WatchdogInner IsInSleep test;
795 * @tc.desc: add testcase
796 * @tc.type: FUNC
797 */
798 HWTEST_F(WatchdogInnerTest, WatchdogInnerTest_IsInSleep_001, TestSize.Level1)
799 {
800 const std::string name = "WatchdogInnerTest_IsInSleep_001";
801 bool taskResult = 0;
__anoncafa5dc20202(void *) 802 XCollieCallback callbackFunc = [&taskResult](void *) {
803 taskResult = 1;
804 };
805
806 WatchdogTask task(name, 0, callbackFunc, nullptr, XCOLLIE_FLAG_DEFAULT);
807 bool ret = WatchdogInner::GetInstance().IsInSleep(task);
808 EXPECT_TRUE(!ret);
809
810 task.bootTimeStart = 0;
811 task.monoTimeStart = 0;
812 ret = WatchdogInner::GetInstance().IsInSleep(task);
813 EXPECT_TRUE(!ret);
814
815 uint64_t bootTimeStart = 0;
816 uint64_t monoTimeStart = 0;
817 CalculateTimes(bootTimeStart, monoTimeStart);
818 uint64_t testValue = 2100;
819 task.bootTimeStart = bootTimeStart;
820 task.monoTimeStart = monoTimeStart + testValue;
821 ret = WatchdogInner::GetInstance().IsInSleep(task);
822 EXPECT_TRUE(ret);
823 }
824
825 /**
826 * @tc.name: WatchdogInner GetAppStartTime test;
827 * @tc.desc: add testcase
828 * @tc.type: FUNC
829 */
830 HWTEST_F(WatchdogInnerTest, WatchdogInnerTest_GetAppStartTime_001, TestSize.Level1)
831 {
832 std::string testStr = "WatchdogInnerTest_GetAppStartTime_001";
833 int64_t time = GetAppStartTime(-1, 0);
834 EXPECT_TRUE(time != 0);
835 }
836
837 /**
838 * @tc.name: WatchdogInner SetSpecifiedProcessName test;
839 * @tc.desc: add testcase
840 * @tc.type: FUNC
841 */
842 HWTEST_F(WatchdogInnerTest, WatchdogInnerTest_SetSpecifiedProcessName_001, TestSize.Level1)
843 {
844 std::string testStr = "WatchdogInnerTest_SetSpecifiedProcessName_001";
845 WatchdogInner::GetInstance().SetSpecifiedProcessName(testStr);
846 EXPECT_EQ(WatchdogInner::GetInstance().GetSpecifiedProcessName(), testStr);
847 }
848
849 /**
850 * @tc.name: WatchdogInner SetScrollState test;
851 * @tc.desc: add testcase
852 * @tc.type: FUNC
853 */
854 HWTEST_F(WatchdogInnerTest, WatchdogInnerTest_SetScrollState_001, TestSize.Level1)
855 {
856 WatchdogInner::GetInstance().SetScrollState(true);
857 EXPECT_EQ(WatchdogInner::GetInstance().isScroll_, true);
858 }
859
860 /**
861 * @tc.name: WatchdogInner UpdateReportTimes Test;
862 * @tc.desc: add teatcase
863 * @tc.type: FUNC
864 */
865 HWTEST_F(WatchdogInnerTest, WatchdogInnerTest_UpdateReportTimes_002, TestSize.Level1)
866 {
867 uint64_t taskId = 1;
868 const char *taskInfo = "Queue_Schedule_Timeout";
869 uint32_t delayedTaskCount = 0;
870 OHOS::system::SetParameter("persist.hiview.jank.reporttimes",
871 "WatchdogInnerUnitTest:120;com.sample.test:60");
872 int32_t checkInterval = 0;
873 int32_t times = 0;
874 std::string bundleName = "test";
875 UpdateReportTimes(bundleName, times, checkInterval);
876 EXPECT_TRUE(times == 0);
877 bundleName = "WatchdogInnerUnitTest";
878 UpdateReportTimes(bundleName, times, checkInterval);
879 EXPECT_TRUE(times == 2);
880 }
881
882 /**
883 * @tc.name: WatchdogInner ClearOldFiles Test;
884 * @tc.desc: add testcase
885 * @tc.type: FUNC
886 */
887 HWTEST_F(WatchdogInnerTest, WatchdogInnerTest_ClearOldFiles_001, TestSize.Level1)
888 {
889 std::string dir = "/data/storage/el2/log/watchdog/";
890 std::vector<FileInfo> fileList;
891 GetFilesByDir(fileList, dir);
892 int deleteCount = ClearOldFiles(fileList);
893 EXPECT_TRUE(deleteCount >= 0);
894 printf("deleteCount: %d\n", deleteCount);
895 dir = "/data/storage/el2/log/watchdog";
896 GetFilesByDir(fileList, dir);
897 deleteCount = ClearOldFiles(fileList);
898 EXPECT_TRUE(deleteCount > 0);
899 }
900
901 /**
902 * @tc.name: WatchdogInner SaveStringToFile Test;
903 * @tc.desc: add testcase
904 * @tc.type: FUNC
905 */
906 HWTEST_F(WatchdogInnerTest, WatchdogInnerTest_SaveStringToFile_001, TestSize.Level1)
907 {
908 std::string filePath = "/";
909 std::string content = "WatchdogInnerTest_SaveStringToFile_001";
910 SaveStringToFile(filePath, content);
911 filePath = "/data/local/tmp/test.txt";
912 bool result = SaveStringToFile(filePath, content);
913 EXPECT_TRUE(result);
914 }
915
916 /**
917 * @tc.name: WatchdogInner StartSample Test;
918 * @tc.desc: add testcase
919 * @tc.type: FUNC
920 */
921 HWTEST_F(WatchdogInnerTest, WatchdogInnerTest_StartSample_001, TestSize.Level1)
922 {
923 std::string path = "test.txt";
924 WatchdogInner::GetInstance().SaveFreezeStackToFile(path, getpid());
925 std::string outFile;
926 WatchdogInner::GetInstance().StartSample(-3000, -300, outFile);
927 EXPECT_TRUE(outFile.empty());
928 WatchdogInner::GetInstance().StartSample(3000, 300, outFile);
929 int count = 0;
930 while (count < 6) {
931 sleep(1);
932 count++;
933 }
934 EXPECT_TRUE(!outFile.empty());
935 }
936
937 /**
938 * @tc.name: WatchdogInner ReadAppStartConfig Test;
939 * @tc.desc: add testcase
940 * @tc.type: FUNC
941 */
942 HWTEST_F(WatchdogInnerTest, WatchdogInnerTest_ReadAppStartConfig_001, TestSize.Level1)
943 {
944 std::string filePath = "/data/test/log/test1.txt";
945 TestCreateFile(filePath);
946 WatchdogInner::GetInstance().ReadAppStartConfig(filePath);
947 EXPECT_TRUE(OHOS::FileExists(filePath));
948 filePath = "/data/log/test11234.txt";
949 WatchdogInner::GetInstance().ReadAppStartConfig(filePath);
950 EXPECT_TRUE(!OHOS::FileExists(filePath));
951 }
952
953 /**
954 * @tc.name: WatchdogInner ParseAppStartParams Test;
955 * @tc.desc: add testcase
956 * @tc.type: FUNC
957 */
958 HWTEST_F(WatchdogInnerTest, WatchdogInnerTest_ParseAppStartParams_001, TestSize.Level1)
959 {
960 std::string eventName = "APP_START_SLOW";
961 std::string configStr = "event_name:APP_START_SLOW,"
962 "threshold:500,collect_times:10,trigger_interval:50,report_times:1,start_time:1750343372595";
963 WatchdogInner::GetInstance().ParseAppStartParams(configStr, eventName);
964 configStr = "event_name:testValue,"
965 "threshold:500,collect_times:10,trigger_interval:50,report_times:1,start_time:1750343372595";
966 WatchdogInner::GetInstance().ParseAppStartParams(configStr, eventName);
967 configStr = ",1234";
968 WatchdogInner::GetInstance().ParseAppStartParams(configStr, eventName);
969 configStr = ",1234";
970 WatchdogInner::GetInstance().ParseAppStartParams(configStr, eventName);
971 configStr = ",:123,";
972 WatchdogInner::GetInstance().ParseAppStartParams(configStr, eventName);
973 EXPECT_TRUE(!WatchdogInner::GetInstance().scrollSlowContent_.enableStartSample);
974 }
975
976 /**
977 * @tc.name: WatchdogInner ParseAppStartParams Test;
978 * @tc.desc: add testcase
979 * @tc.type: FUNC
980 */
981 HWTEST_F(WatchdogInnerTest, WatchdogInnerTest_ParseAppStartParams_002, TestSize.Level1)
982 {
983 std::string eventName = "APP_START_SLOW";
984 std::string configStr = "event_name:APP_START_SLOW,start_time:1752580699000,"
985 "collect_times:10,trigger_interval:50,report_times:1,start_time:1750343372595";
986 WatchdogInner::GetInstance().ParseAppStartParams(configStr, eventName);
987 configStr = "event_name:APP_START_SLOW,start_time:1752580699000,"
988 "threshold:500,trigger_interval:50,report_times:1,start_time:1750343372595";
989 WatchdogInner::GetInstance().ParseAppStartParams(configStr, eventName);
990 configStr = "event_name:APP_START_SLOW,start_time:1752580699000,"
991 "threshold:500,collect_times:10,report_times:1,start_time:1750343372595";
992 WatchdogInner::GetInstance().ParseAppStartParams(configStr, eventName);
993 configStr = "event_name:APP_START_SLOW,,start_time:1752580699000,"
994 "threshold:500,collect_times:10,trigger_interval:50,start_time:1750343372595";
995 WatchdogInner::GetInstance().ParseAppStartParams(configStr, eventName);
996 configStr = "event_name:APP_START_SLOW,start_time:1752580699000,"
997 "threshold:500,collect_times:10,trigger_interval:50,report_times:1,startup_duration:5000";
998 WatchdogInner::GetInstance().ParseAppStartParams(configStr, eventName);
999 EXPECT_TRUE(WatchdogInner::GetInstance().startSlowContent_.enableStartSample);
1000 }
1001
1002 /**
1003 * @tc.name: WatchdogInner ParseAppStartParams Test;
1004 * @tc.desc: add testcase
1005 * @tc.type: FUNC
1006 */
1007 HWTEST_F(WatchdogInnerTest, WatchdogInnerTest_ParseAppStartParams_003, TestSize.Level1)
1008 {
1009 std::string eventName = "SLIDING_JANK";
1010 std::string configStr = "event_name:SLIDING_JANK,start_time:1752580699000,"
1011 "threshold:500,collect_times:10,trigger_interval:50,report_times:1";
1012 WatchdogInner::GetInstance().ParseAppStartParams(configStr, eventName);
1013 EXPECT_TRUE(WatchdogInner::GetInstance().scrollSlowContent_.enableStartSample);
1014 }
1015
1016 /**
1017 * @tc.name: WatchdogInner CheckSample Test;
1018 * @tc.desc: add testcase
1019 * @tc.type: FUNC
1020 */
1021 HWTEST_F(WatchdogInnerTest, WatchdogInnerTest_CheckSample_001, TestSize.Level1)
1022 {
1023 WatchdogInner::GetInstance().isScroll_ = true;
1024 TimePoint endTime = std::chrono::steady_clock::now();
1025 int64_t durationTime = 1000;
1026 bool result = WatchdogInner::GetInstance().CheckSample(endTime, durationTime);
1027 EXPECT_TRUE(!result);
1028 WatchdogInner::GetInstance().isScroll_ = false;
1029 result = WatchdogInner::GetInstance().CheckSample(endTime, durationTime);
1030 EXPECT_TRUE(!result);
1031 }
1032
1033 /**
1034 * @tc.name: WatchdogInner EnableAppStartSample Test;
1035 * @tc.desc: add testcase
1036 * @tc.type: FUNC
1037 */
1038 HWTEST_F(WatchdogInnerTest, WatchdogInnerTest_EnableAppStartSample_001, TestSize.Level1)
1039 {
1040 bool isScroll = true;
1041 int64_t durationTime = 1000;
1042 AppStartContent startContent;
1043 bool result = WatchdogInner::GetInstance().EnableAppStartSample(startContent, durationTime, isScroll);
1044 EXPECT_TRUE(!result);
1045 isScroll = false;
1046 TestInitAppStartSample(startContent);
1047 int ret = TestCreateFile(APP_START_CONFIG);
1048 EXPECT_EQ(ret, 0);
1049 result = WatchdogInner::GetInstance().EnableAppStartSample(startContent, durationTime, isScroll);
1050 EXPECT_TRUE(!result);
1051 }
1052
1053 /**
1054 * @tc.name: WatchdogInner EnableAppStartSample Test;
1055 * @tc.desc: add testcase
1056 * @tc.type: FUNC
1057 */
1058 HWTEST_F(WatchdogInnerTest, WatchdogInnerTest_EnableAppStartSample_002, TestSize.Level1)
1059 {
1060 bool isScroll = false;
1061 int64_t durationTime = 1000;
1062 AppStartContent startContent;
1063 startContent.startUpDuration = 0;
1064 bool result = WatchdogInner::GetInstance().EnableAppStartSample(startContent, durationTime, isScroll);
1065 EXPECT_TRUE(!result);
1066 startContent.enableStartSample = true;
1067 result = WatchdogInner::GetInstance().EnableAppStartSample(startContent, durationTime, isScroll);
1068 EXPECT_TRUE(!result);
1069 startContent.enableStartSample = false;
1070 int ret = TestCreateFile(APP_START_CONFIG);
1071 EXPECT_EQ(ret, 0);
1072 WatchdogInner::GetInstance().watchdogStartTime_ = GetCurrentTickMillseconds();
1073 result = WatchdogInner::GetInstance().EnableAppStartSample(startContent, durationTime, isScroll);
1074 EXPECT_TRUE(!result);
1075 WatchdogInner::GetInstance().watchdogStartTime_ = 0;
1076 result = WatchdogInner::GetInstance().EnableAppStartSample(startContent, durationTime, isScroll);
1077 EXPECT_TRUE(!result);
1078 startContent.reportTimes = 1;
1079 result = WatchdogInner::GetInstance().EnableAppStartSample(startContent, durationTime, isScroll);
1080 EXPECT_TRUE(!result);
1081 startContent.isStartSampleEnabled = true;
1082 result = WatchdogInner::GetInstance().EnableAppStartSample(startContent, durationTime, isScroll);
1083 EXPECT_TRUE(!result);
1084 startContent.threshold = 1000;
1085 result = WatchdogInner::GetInstance().EnableAppStartSample(startContent, durationTime, isScroll);
1086 EXPECT_TRUE(!result);
1087 }
1088 } // namespace HiviewDFX
1089 } // namespace OHOS
1090