1 /*
2 * Copyright (c) 2021-2022 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 /* This file contains faultlog daemon system test cases. */
17
18 #include "faultloggerd_system_test.h"
19
20 #include <cerrno>
21 #include <csignal>
22 #include <cstdio>
23 #include <cstring>
24 #include <ctime>
25 #include <dirent.h>
26 #include <fcntl.h>
27 #include <fstream>
28 #include <iostream>
29 #include <memory>
30 #include <mutex>
31 #include <pthread.h>
32 #include <securec.h>
33 #include <stdlib.h>
34 #include <string>
35 #include <sys/mman.h>
36 #include <sys/prctl.h>
37 #include <sys/stat.h>
38 #include <sys/types.h>
39 #include <sys/wait.h>
40 #include <thread>
41 #include <unistd.h>
42 #include <vector>
43 #include "dfx_dump_catcher.h"
44 #include "directory_ex.h"
45 #include "file_ex.h"
46 #include "syscall.h"
47
48 /* This files contains faultlog st test case modules. */
49
50 using namespace OHOS::HiviewDFX;
51 using namespace testing::ext;
52 using namespace std;
53
54 namespace {
55 static const int BMS_UID = 1000;
56 static const int OTHER_UID = 10000;
57 static const int NUMBER_ONE = 1;
58 static const int NUMBER_TWO = 2;
59 static const int NUMBER_THREE = 3;
60 static const int NUMBER_FOUR = 4;
61 static const int NUMBER_SIXTY = 60;
62 static const int NUMBER_FIFTY = 50;
63 static const string DEFAULT_PID_MAX = "32768";
64 static const string DEFAULT_TID_MAX = "8825";
65 static mutex g_mutex;
66 }
67
SetUpTestCase(void)68 void FaultLoggerdSystemTest::SetUpTestCase(void)
69 {
70 }
71
TearDownTestCase(void)72 void FaultLoggerdSystemTest::TearDownTestCase(void)
73 {
74 }
75
SetUp(void)76 void FaultLoggerdSystemTest::SetUp(void)
77 {
78 }
79
TearDown(void)80 void FaultLoggerdSystemTest::TearDown(void)
81 {
82 }
83
KillCrasherLoopForSomeCase(int type)84 void FaultLoggerdSystemTest::KillCrasherLoopForSomeCase(int type)
85 {
86 int rootuid = 0;
87 int sysuid = BMS_UID;
88 if (type == NUMBER_ONE) {
89 setuid(sysuid);
90 system(("kill -9 " + std::to_string(FaultLoggerdSystemTest::loopSysPid)).c_str());
91 } else if (type == NUMBER_TWO) {
92 setuid(rootuid);
93 system(("kill -9 " + std::to_string(FaultLoggerdSystemTest::loopRootPid)).c_str());
94 } else if (type == NUMBER_THREE) {
95 setuid(rootuid);
96 system(("kill -9 " + std::to_string(FaultLoggerdSystemTest::loopAppPid)).c_str());
97 } else {
98 setuid(sysuid);
99 system(("kill -9 " + std::to_string(FaultLoggerdSystemTest::unsigLoopSysPid)).c_str());
100 }
101 }
102
103 std::string FaultLoggerdSystemTest::rootTid[ARRAY_SIZE_HUNDRED] = { "", };
104 std::string FaultLoggerdSystemTest::appTid[ARRAY_SIZE_HUNDRED] = { "", };
105 std::string FaultLoggerdSystemTest::sysTid[ARRAY_SIZE_HUNDRED] = { "", };
106 std::string FaultLoggerdSystemTest::testTid[ARRAY_SIZE_HUNDRED] = { "", };
107 int FaultLoggerdSystemTest::loopSysPid = 0;
108 int FaultLoggerdSystemTest::loopRootPid = 0;
109 int FaultLoggerdSystemTest::loopCppPid = 0;
110 int FaultLoggerdSystemTest::loopAppPid = 0;
111 int FaultLoggerdSystemTest::count = 0;
112 char FaultLoggerdSystemTest::resultBufShell[ARRAY_SIZE_HUNDRED] = { 0, };
113 unsigned int FaultLoggerdSystemTest::unsigLoopSysPid = 0;
114
GetPidMax()115 std::string FaultLoggerdSystemTest::GetPidMax()
116 {
117 const string path = "/proc/sys/kernel/pid_max";
118 std::ifstream file(path);
119 if (!file) {
120 GTEST_LOG_(INFO) << "file not exists";
121 return DEFAULT_PID_MAX;
122 } else {
123 std::string pidMax;
124 file >> pidMax;
125 return pidMax;
126 }
127 return DEFAULT_PID_MAX;
128 }
129
GetTidMax()130 std::string FaultLoggerdSystemTest::GetTidMax()
131 {
132 const string path = "/proc/sys/kernel/threads-max";
133 std::ifstream file(path);
134 if (!file) {
135 GTEST_LOG_(INFO) << "file not exists";
136 return DEFAULT_TID_MAX;
137 } else {
138 std::string tidMax;
139 file >> tidMax;
140 return tidMax;
141 }
142 return DEFAULT_TID_MAX;
143 }
144
ProcessDumpCommands(const std::string cmds)145 std::string FaultLoggerdSystemTest::ProcessDumpCommands(const std::string cmds)
146 {
147 GTEST_LOG_(INFO) << "threadCMD = " << cmds;
148 FILE *procFileInfo = nullptr;
149 std::string cmdLog = "";
150 procFileInfo = popen(cmds.c_str(), "r");
151 if (procFileInfo == nullptr) {
152 perror("popen execute failed");
153 return cmdLog;
154 }
155 while (fgets(resultBufShell, sizeof(resultBufShell), procFileInfo) != nullptr) {
156 cmdLog = cmdLog + resultBufShell;
157 }
158 pclose(procFileInfo);
159 return cmdLog;
160 }
161
162 // commandStatus: 0 C 1 CPP
ForkAndRunCommands(const std::vector<std::string> & cmds,int commandStatus)163 std::string FaultLoggerdSystemTest::ForkAndRunCommands(const std::vector<std::string>& cmds, int commandStatus)
164 {
165 pid_t pid = fork();
166 if (pid < 0) {
167 return "";
168 } else if (pid == 0) {
169 std::vector<char *> argv;
170 for (const auto &arg : cmds) {
171 argv.push_back(const_cast<char *>(arg.c_str()));
172 }
173 argv.push_back(0);
174 printf("ForkAndRunCommands %d \n", getpid());
175 if (commandStatus == 0) {
176 execv("/data/crasher_c", &argv[0]);
177 } else {
178 execv("/data/crasher_cpp", &argv[0]);
179 }
180 }
181
182 constexpr time_t maxWaitingTime = NUMBER_SIXTY; // 60 seconds
183 time_t remainedTime = maxWaitingTime;
184 while (remainedTime > 0) {
185 time_t startTime = time(nullptr);
186 int status = 0;
187 waitpid(pid, &status, WNOHANG);
188 if (WIFEXITED(status)) {
189 break;
190 }
191 int sleepSecond = 1;
192 sleep(sleepSecond);
193 time_t duration = time(nullptr) - startTime;
194 remainedTime = (remainedTime > duration) ? (remainedTime - duration) : 0;
195 }
196 printf("forked pid:%d \n", pid);
197 return std::to_string(pid);
198 }
199
CountLines(std::string FileName)200 int FaultLoggerdSystemTest::CountLines(std::string FileName)
201 {
202 ifstream ReadFile;
203 std::string tmpuseValue;
204 ReadFile.open(FileName.c_str(), ios::in);
205 if (ReadFile.fail()) {
206 return 0;
207 } else {
208 int n = 0;
209 while (getline(ReadFile, tmpuseValue, '\n')) {
210 n++;
211 }
212 ReadFile.close();
213 return n;
214 }
215 }
216
IsDigit(std::string pid)217 bool FaultLoggerdSystemTest::IsDigit(std::string pid)
218 {
219 bool flag = true;
220 for (unsigned int j = 0; j < pid.length() - 1; j++) {
221 if (!isdigit(pid[j])) {
222 flag = false;
223 break;
224 }
225 }
226 return flag;
227 }
228
GetLogFileName(const std::string & prefix)229 static std::string GetLogFileName(const std::string& prefix)
230 {
231 std::string filePath;
232 std::vector<std::string> files;
233 OHOS::GetDirFiles("/data/log/faultlog/temp/", files);
234 for (const auto& file : files) {
235 if (file.find(prefix) != std::string::npos) {
236 filePath = file;
237 }
238 }
239 return filePath;
240 }
241
242 // commandStatus: 0 C 1 CPP
GetfileNamePrefix(std::string ErrorCMD,int commandStatus)243 std::string FaultLoggerdSystemTest::GetfileNamePrefix(std::string ErrorCMD, int commandStatus)
244 {
245 std::vector<std::string> cmds {"crasher_c", ErrorCMD};
246 std::string pid = FaultLoggerdSystemTest::ForkAndRunCommands(cmds, commandStatus);
247 int sleepSecond = 5;
248 sleep(sleepSecond);
249 std::string prefix = "cppcrash-" + pid;
250 std::string filePath = GetLogFileName(prefix);
251 return filePath + " " + pid;
252 }
253
254 // commandStatus: 0 C 1 CPP
GetstackfileNamePrefix(std::string ErrorCMD,int commandStatus)255 std::string FaultLoggerdSystemTest::GetstackfileNamePrefix(std::string ErrorCMD, int commandStatus)
256 {
257 std::vector<std::string> cmds { "crasher_c", ErrorCMD };
258 std::string pid = FaultLoggerdSystemTest::ForkAndRunCommands(cmds, commandStatus);
259 int sleepSecond = 5;
260 sleep(sleepSecond);
261 std::string prefix = "stacktrace-" + pid;
262 std::string filePath = GetLogFileName(prefix);
263 return filePath + " " + pid;
264 }
265
CheckKeywords(std::string & filePath,std::string * keywords,int length,int minRegIdx)266 int FaultLoggerdSystemTest::CheckKeywords(std::string& filePath, std::string *keywords, int length, int minRegIdx)
267 {
268 ifstream file;
269 file.open(filePath.c_str(), ios::in);
270 long lines = FaultLoggerdSystemTest::CountLines(filePath);
271 std::vector<string> t(lines * NUMBER_FOUR);
272 int i = 0;
273 int j = 0;
274 string::size_type idx;
275 int count = 0;
276 int maxRegIdx = minRegIdx + REGISTERS_NUM + 1;
277 while (!file.eof()) {
278 file >> t.at(i);
279 idx = t.at(i).find(keywords[j]);
280 if (idx != string::npos) {
281 GTEST_LOG_(INFO) << t.at(i);
282 if (minRegIdx != -1 && j > minRegIdx && j < maxRegIdx) { // -1 : do not check register value
283 if (t.at(i).size() < REGISTERS_LENGTH) {
284 count--;
285 }
286 }
287 count++;
288 j++;
289 if (j == length) {
290 break;
291 }
292 continue;
293 }
294 i++;
295 }
296 file.close();
297 return count == length ? 0 : 1;
298 }
299
CheckCountNum(std::string & filePath,std::string & pid,std::string & ErrorCMD)300 int FaultLoggerdSystemTest::CheckCountNum(std::string& filePath, std::string& pid, std::string& ErrorCMD)
301 {
302 std::map<std::string, std::string> CmdKey = {
303 #if defined(__LP64__)
304 { std::string("triSIGILL"), std::string("SIGTRAP") },
305 { std::string("triSIGTRAP"), std::string("SIGILL") },
306 #else
307 { std::string("triSIGILL"), std::string("SIGILL") },
308 { std::string("triSIGTRAP"), std::string("SIGTRAP") },
309 #endif
310 { std::string("triSIGSEGV"), std::string("SIGSEGV") },
311 { std::string("MaxStack"), std::string("SIGSEGV") },
312 { std::string("MaxMethod"), std::string("SIGSEGV") },
313 { std::string("STACKTRACE"), std::string("Tid") },
314 { std::string("STACKOF"), std::string("SIGSEGV") },
315 };
316
317 std::map<std::string, std::string>::iterator key;
318 key = CmdKey.find(ErrorCMD);
319 if (key != CmdKey.end()) {
320 ErrorCMD = key->second;
321 }
322 string log[] = {
323 "Pid:", "Uid", ":crasher", ErrorCMD, "Tid:", "#00", "Registers:", REGISTERS, "FaultStack:", "Maps:", "/crasher"
324 };
325 log[0] = log[0] + pid;
326 int minRegIdx = 6;
327 return CheckKeywords(filePath, log, sizeof(log) / sizeof(log[0]), minRegIdx);
328 }
329
CheckCountNumAbort(std::string & filePath,std::string & pid)330 int FaultLoggerdSystemTest::CheckCountNumAbort(std::string& filePath, std::string& pid)
331 {
332 string log[] = {
333 "Pid:", "Uid", ":crasher", "SIGABRT", "LastFatalMessage:", "ABORT!", "Tid:", "#00", "Registers:",
334 REGISTERS, "FaultStack:", "Maps:", "/crasher"
335 };
336 log[0] = log[0] + pid;
337 int minRegIdx = 8;
338 return CheckKeywords(filePath, log, sizeof(log) / sizeof(log[0]), minRegIdx);
339 }
340
CheckCountNumPCZero(std::string & filePath,std::string & pid)341 int FaultLoggerdSystemTest::CheckCountNumPCZero(std::string& filePath, std::string& pid)
342 {
343 string log[] = {
344 "Pid:", "Uid", ":crasher", "SIGSEGV", "Tid:", "#00", "Registers:", REGISTERS, "FaultStack:", "Maps:", "/crasher"
345 };
346 log[0] = log[0] + pid;
347 int minRegIdx = 6;
348 return CheckKeywords(filePath, log, sizeof(log) / sizeof(log[0]), minRegIdx);
349 }
350
CheckCountNumOverStack(std::string & filePath,std::string & pid)351 int FaultLoggerdSystemTest::CheckCountNumOverStack(std::string& filePath, std::string& pid)
352 {
353 string log[] = {
354 "Pid:", "Uid", ":crasher", "SIGSEGV", "Tid:", "#56", "Registers:", REGISTERS, "FaultStack:", "Maps:", "/crasher"
355 };
356 log[0] = log[0] + pid;
357 int minRegIdx = 6;
358 return CheckKeywords(filePath, log, sizeof(log) / sizeof(log[0]), minRegIdx);
359 }
360
CheckCountNumMultiThread(std::string & filePath,std::string & pid)361 int FaultLoggerdSystemTest::CheckCountNumMultiThread(std::string& filePath, std::string& pid)
362 {
363 string log[] = {
364 "Pid:", "Uid", ":crasher", "SIGSEGV", "Tid:", "#00",
365 "Registers:", REGISTERS, "FaultStack:", "Maps:",
366 "/crasher"
367 };
368 log[0] = log[0] + pid;
369 int minRegIdx = 6;
370 return CheckKeywords(filePath, log, sizeof(log) / sizeof(log[0]), minRegIdx);
371 }
372
GetStackTop(void)373 std::string FaultLoggerdSystemTest::GetStackTop(void)
374 {
375 ifstream spFile;
376 spFile.open("sp");
377 std::string sp;
378 spFile >> sp;
379 GTEST_LOG_(INFO) << "sp:" << sp;
380 spFile.close();
381 int ret = remove("sp");
382 if (ret != 0) {
383 printf("remove failed!");
384 }
385 return sp;
386 }
387
CheckCountNumStackTop(std::string & filePath,std::string & pid,std::string & ErrorCMD)388 int FaultLoggerdSystemTest::CheckCountNumStackTop(std::string& filePath, std::string& pid, std::string& ErrorCMD)
389 {
390 std::string sp = FaultLoggerdSystemTest::GetStackTop();
391 std::map<std::string, std::string> CmdKey = {
392 #if defined(__LP64__)
393 { std::string("StackTop"), std::string("SIGTRAP") },
394 #else
395 { std::string("StackTop"), std::string("SIGILL") },
396 #endif
397 };
398 std::map<std::string, std::string>::iterator key;
399 key = CmdKey.find(ErrorCMD);
400 if (key != CmdKey.end()) {
401 ErrorCMD = key->second;
402 }
403 string log[] = {
404 "Pid:", "Uid", ":crasher", ErrorCMD, "Tid:", "#00", "Registers:", REGISTERS, "FaultStack:", "Maps:", "/crasher"
405 };
406 log[0] = log[0] + pid;
407 int minRegIdx = 6;
408 return CheckKeywords(filePath, log, sizeof(log) / sizeof(log[0]), minRegIdx);
409 }
410
CheckStacktraceCountNum(std::string & filePath,std::string & pid)411 int FaultLoggerdSystemTest::CheckStacktraceCountNum(std::string& filePath, std::string& pid)
412 {
413 string log[] = {
414 "Tid:", ":crasher", "#00",
415 };
416 log[0] = log[0] + pid;
417 return CheckKeywords(filePath, log, sizeof(log) / sizeof(log[0]), -1); // -1 : do not check register value
418 }
419
ForkAndCommands(int crasherType,int udid)420 std::string FaultLoggerdSystemTest::ForkAndCommands(int crasherType, int udid)
421 {
422 setuid(udid);
423 if (crasherType == 0) {
424 system("/data/crasher_c thread-Loop &");
425 } else {
426 system("/data/crasher_cpp thread-Loop &");
427 }
428 std::string procCMD = "pgrep 'crasher'";
429 GTEST_LOG_(INFO) << "threadCMD = " << procCMD;
430 FILE *procFileInfo = nullptr;
431 procFileInfo = popen(procCMD.c_str(), "r");
432 if (procFileInfo == nullptr) {
433 perror("popen execute failed");
434 exit(1);
435 }
436 if (udid == 0) { // root
437 int i = 0;
438 while ((fgets(resultBufShell, sizeof(resultBufShell), procFileInfo) != nullptr) && (i < NUMBER_SIXTY)) {
439 std::string pidLog = resultBufShell;
440 GTEST_LOG_(INFO) << "pidList[" << i << "]" << pidLog << ".";
441 if (IsDigit(pidLog) == false) {
442 continue;
443 }
444 if (loopSysPid == atoi(pidLog.c_str())) {
445 GTEST_LOG_(INFO) << loopSysPid;
446 } else {
447 if (crasherType == 1) {
448 FaultLoggerdSystemTest::loopCppPid = atoi(pidLog.c_str());
449 } else {
450 FaultLoggerdSystemTest::loopRootPid = atoi(pidLog.c_str());
451 }
452 }
453 }
454 GTEST_LOG_(INFO) << "Root ID: " << FaultLoggerdSystemTest::loopRootPid;
455 } else if (udid == BMS_UID) { // sys
456 while (fgets(resultBufShell, sizeof(resultBufShell), procFileInfo) != nullptr) {
457 std::string pidLog = resultBufShell;
458 loopSysPid = atoi(pidLog.c_str());
459 GTEST_LOG_(INFO) << "System ID: " << loopSysPid;
460 }
461 } else { // app
462 while (fgets(resultBufShell, sizeof(resultBufShell), procFileInfo) != nullptr) {
463 std::string pidLog = resultBufShell;
464 if (loopSysPid == atoi(pidLog.c_str())) {
465 GTEST_LOG_(INFO) << loopSysPid;
466 } else if (loopRootPid == atoi(pidLog.c_str())) {
467 GTEST_LOG_(INFO) << loopRootPid;
468 } else {
469 loopAppPid = atoi(pidLog.c_str());
470 }
471 }
472 GTEST_LOG_(INFO) << "APP ID: " << loopAppPid;
473 }
474 pclose(procFileInfo);
475 return std::to_string(loopSysPid);
476 }
477
478 // create crasher loop for: 1. system; 2. root; 3.app; 4. root+cpp
StartCrasherLoop(int type)479 void FaultLoggerdSystemTest::StartCrasherLoop(int type)
480 {
481 if (type == NUMBER_ONE) {
482 int crasherType = 0;
483 int uidSetting = BMS_UID;
484 setuid(uidSetting);
485 FaultLoggerdSystemTest::ForkAndCommands(crasherType, uidSetting);
486 if (loopSysPid == 0) {
487 exit(0);
488 }
489
490 int sleepSecond = 5;
491 usleep(sleepSecond);
492 std::string procCMD = "ls /proc/" + std::to_string(loopSysPid) + "/task";
493 FILE *procFileInfo = nullptr;
494 procFileInfo = popen(procCMD.c_str(), "r");
495 if (procFileInfo == nullptr) {
496 perror("popen execute failed");
497 exit(1);
498 }
499 int sysTidCount = 0;
500 while (fgets(resultBufShell, sizeof(resultBufShell), procFileInfo) != nullptr) {
501 sysTid[sysTidCount] = resultBufShell;
502 GTEST_LOG_(INFO) << "procFileInfo print info = " << resultBufShell;
503 sysTidCount = sysTidCount + 1;
504 }
505 int otheruid = OTHER_UID;
506 setuid(otheruid);
507 pclose(procFileInfo);
508 } else if (type == NUMBER_TWO) {
509 int crasherType = 0;
510 int rootuid = 0;
511 setuid(rootuid);
512 FaultLoggerdSystemTest::ForkAndCommands(crasherType, rootuid);
513 if (loopRootPid == 0) {
514 exit(0);
515 }
516
517 int sleepSecond = 5;
518 usleep(sleepSecond);
519 std::string procCMD = "ls /proc/" + std::to_string(loopRootPid) + "/task";
520 FILE *procFileInfo = nullptr;
521 procFileInfo = popen(procCMD.c_str(), "r");
522 if (procFileInfo == nullptr) {
523 perror("popen execute failed");
524 exit(1);
525 }
526 int rootTidCount = 0;
527 while (fgets(resultBufShell, sizeof(resultBufShell), procFileInfo) != nullptr) {
528 rootTid[rootTidCount] = resultBufShell;
529 GTEST_LOG_(INFO) << "procFileInfo print info = " << resultBufShell;
530 rootTidCount = rootTidCount + 1;
531 }
532 int otheruid = OTHER_UID;
533 setuid(otheruid);
534 pclose(procFileInfo);
535 } else if (type == NUMBER_THREE) {
536 int crasherType = 0;
537 int uidSetting = OTHER_UID;
538 setuid(uidSetting);
539 FaultLoggerdSystemTest::ForkAndCommands(crasherType, uidSetting);
540 if (loopAppPid == 0) {
541 exit(0);
542 }
543
544 int sleepSecond = 5;
545 usleep(sleepSecond);
546 std::string procCMD = "ls /proc/" + std::to_string(loopAppPid) + "/task";
547 FILE *procFileInfo = nullptr;
548 procFileInfo = popen(procCMD.c_str(), "r");
549 if (procFileInfo == nullptr) {
550 perror("popen execute failed");
551 exit(1);
552 }
553 int appTidCount = 0;
554 while (fgets(resultBufShell, sizeof(resultBufShell), procFileInfo) != nullptr) {
555 appTid[appTidCount] = resultBufShell;
556 GTEST_LOG_(INFO) << "procFileInfo print info = " << resultBufShell;
557 appTidCount = appTidCount + 1;
558 }
559 pclose(procFileInfo);
560 } else if (type == NUMBER_FOUR) {
561 int crasherType = 1;
562 int otheruid = OTHER_UID;
563 setuid(otheruid);
564 FaultLoggerdSystemTest::ForkAndCommands(crasherType, otheruid);
565 DfxDumpCatcher dumplog;
566 std::string msg = "";
567 dumplog.DumpCatch(loopAppPid, 0, msg);
568 int sleepSecond = 5;
569 sleep(sleepSecond);
570 std::string procCMD = "ls /proc/" + std::to_string(loopAppPid) + "/task";
571 FILE *procFileInfo = nullptr;
572
573 procFileInfo = popen(procCMD.c_str(), "r");
574 if (procFileInfo == nullptr) {
575 perror("popen execute failed");
576 exit(1);
577 }
578 while (fgets(resultBufShell, sizeof(resultBufShell), procFileInfo) != nullptr) {
579 GTEST_LOG_(INFO) << "procFileInfo print info = " << resultBufShell;
580 }
581 pclose(procFileInfo);
582 }
583 }
584
StartCrasherLoopForUnsingPidAndTid(int crasherType)585 void FaultLoggerdSystemTest::StartCrasherLoopForUnsingPidAndTid(int crasherType)
586 {
587 int sysTidCount = 0;
588 int uidSetting = BMS_UID;
589 setuid(uidSetting);
590 if (crasherType == 0) {
591 system("/data/crasher_c thread-Loop &");
592 } else {
593 system("/data/crasher_cpp thread-Loop &");
594 }
595 std::string procCMDOne = "pgrep 'crasher'";
596 GTEST_LOG_(INFO) << "threadCMD = " << procCMDOne;
597 FILE *procFileInfoOne = nullptr;
598 procFileInfoOne = popen(procCMDOne.c_str(), "r");
599 if (procFileInfoOne == nullptr) {
600 perror("popen execute failed");
601 exit(1);
602 }
603 while (fgets(resultBufShell, sizeof(resultBufShell), procFileInfoOne) != nullptr) {
604 std::string pidLog = resultBufShell;
605 unsigLoopSysPid = atoi(pidLog.c_str());
606 GTEST_LOG_(INFO) << "System ID: " << unsigLoopSysPid;
607 }
608 pclose(procFileInfoOne);
609 if (unsigLoopSysPid == 0) {
610 exit(0);
611 }
612 int sleepSecond = 5;
613 usleep(sleepSecond);
614 std::string procCMDTwo = "ls /proc/" + std::to_string(unsigLoopSysPid) + "/task";
615 FILE *procFileInfoTwo = nullptr;
616 procFileInfoTwo = popen(procCMDTwo.c_str(), "r");
617 if (procFileInfoTwo == nullptr) {
618 perror("popen execute failed");
619 exit(1);
620 }
621 while (fgets(resultBufShell, sizeof(resultBufShell), procFileInfoTwo) != nullptr) {
622 sysTid[sysTidCount] = resultBufShell;
623 GTEST_LOG_(INFO) << "procFileInfoTwo print info = " << resultBufShell;
624 sysTidCount = sysTidCount + 1;
625 }
626 pclose(procFileInfoTwo);
627 }
628
Trim(std::string & str)629 void FaultLoggerdSystemTest::Trim(std::string & str)
630 {
631 std::string blanks("\f\v\r\t\n ");
632 str.erase(0, str.find_first_not_of(blanks));
633 str.erase(str.find_last_not_of(blanks) + 1);
634 }
635
CheckCountNumKill11(std::string & filePath,std::string & pid)636 int FaultLoggerdSystemTest::CheckCountNumKill11(std::string& filePath, std::string& pid)
637 {
638 string log[] = {
639 "Pid:", "Uid", ":foundation", "SIGSEGV", "Tid:", "#00", "Registers:", REGISTERS,
640 "FaultStack:","Maps:"
641 };
642 log[0] = log[0] + pid;
643 int minRegIdx = 6;
644 return CheckKeywords(filePath, log, sizeof(log) / sizeof(log[0]), minRegIdx);
645 }
646
crashThread(int threadID)647 int FaultLoggerdSystemTest::crashThread(int threadID)
648 {
649 GTEST_LOG_(INFO) << "threadID :" << threadID;
650 int i;
651 for (i = 0; i < NUMBER_FIFTY; i++) {
652 system("./crasher_c CrashTest &");
653 }
654 sleep(1);
655 return 0;
656 }
657
getApplyPid(std::string applyName)658 int FaultLoggerdSystemTest::getApplyPid(std::string applyName)
659 {
660 std::string procCMD = "pgrep '" + applyName + "'";
661 GTEST_LOG_(INFO) << "threadCMD = " << procCMD;
662 FILE *procFileInfo = nullptr;
663 procFileInfo = popen(procCMD.c_str(), "r");
664 if (procFileInfo == nullptr) {
665 perror("popen execute failed");
666 exit(1);
667 }
668 std::string applyPid;
669 while (fgets(resultBufShell, sizeof(resultBufShell), procFileInfo) != nullptr) {
670 applyPid = resultBufShell;
671 GTEST_LOG_(INFO) << "applyPid: " << applyPid;
672 }
673 pclose(procFileInfo);
674 int intApplyPid = std::atoi(applyPid.c_str());
675 return intApplyPid;
676 }
677
GetCmdResultFromPopen(const std::string & cmd)678 std::string FaultLoggerdSystemTest::GetCmdResultFromPopen(const std::string& cmd)
679 {
680 if (cmd.empty()) {
681 return "";
682 }
683
684 FILE* fp = popen(cmd.c_str(), "r");
685 if (fp == nullptr) {
686 return "";
687 }
688 const int bufSize = 128;
689 char buffer[bufSize];
690 std::string result = "";
691 while (!feof(fp)) {
692 if (fgets(buffer, bufSize - 1, fp) != nullptr) {
693 result += buffer;
694 }
695 }
696 pclose(fp);
697 return result;
698 }
699
GetServicePid(const std::string & serviceName)700 int FaultLoggerdSystemTest::GetServicePid(const std::string& serviceName)
701 {
702 std::string cmd = "pidof " + serviceName;
703 std::string pidStr = GetCmdResultFromPopen(cmd);
704 int32_t pid = 0;
705 std::stringstream pidStream(pidStr);
706 pidStream >> pid;
707 printf("the pid of service(%s) is %s \n", serviceName.c_str(), pidStr.c_str());
708 return pid;
709 }
710
LaunchTestHap(const std::string & abilityName,const std::string & bundleName)711 int FaultLoggerdSystemTest::LaunchTestHap(const std::string& abilityName, const std::string& bundleName)
712 {
713 std::string launchCmd = "/system/bin/aa start -a " + abilityName + " -b " + bundleName;
714 (void)GetCmdResultFromPopen(launchCmd);
715 sleep(2); // 2 : sleep 2s
716 return GetServicePid(bundleName);
717 }
718
dumpCatchThread(int threadID)719 void FaultLoggerdSystemTest::dumpCatchThread(int threadID)
720 {
721 std::string accountmgr = "accountmgr";
722 int accountmgrPid = FaultLoggerdSystemTest::getApplyPid(accountmgr);
723 DfxDumpCatcher dumplog;
724 std::string msg = "";
725 bool ret = dumplog.DumpCatch(accountmgrPid, 0, msg);
726 GTEST_LOG_(INFO) << "ret:" << ret;
727 if (ret == true) {
728 FaultLoggerdSystemTest::count++;
729 }
730 }
731
732 namespace {
733 #ifdef __pre__
734 /**
735 * @tc.name: FaultLoggerdSystemTest0010_pre
736 * @tc.desc: test CPP crasher application: Multithreading
737 * @tc.type:
738 */
739 HWTEST_F (FaultLoggerdSystemTest, FaultLoggerdSystemTest0010_pre, TestSize.Level2)
740 {
741 GTEST_LOG_(INFO) << "FaultLoggerdSystemTest0010_pre: start.";
742 for (int i = 0; i < 10; i++) {
743 g_mutex.lock();
744 std::thread (FaultLoggerdSystemTest::dumpCatchThread, i).join();
745 sleep(NUMBER_TWO);
746 g_mutex.unlock();
747 }
748 EXPECT_EQ(FaultLoggerdSystemTest::count, 10) << "FaultLoggerdSystemTest0010_pre Failed";
749 if (count == 10) {
750 std::ofstream fout;
751 fout.open("result", ios::app);
752 fout << "sucess!" << std::endl;
753 fout.close();
754 }
755 GTEST_LOG_(INFO) << "FaultLoggerdSystemTest0010_pre: end.";
756
757 }
758 #endif
759
760 #ifndef __pre__
761 static const int NUMBER_TEN = 10;
762
763 /**
764 * @tc.name: FaultLoggerdSystemTest0010
765 * @tc.desc: test CPP crasher application: Multi process and Multithreading
766 * @tc.type:
767 */
768 HWTEST_F (FaultLoggerdSystemTest, FaultLoggerdSystemTest0010, TestSize.Level2)
769 {
770 GTEST_LOG_(INFO) << "FaultLoggerdSystemTest0010: start.";
771 for (int i = 0; i < 10; i++) {
772 system("/data/test_faultloggerd_pre --gtest_filter=FaultLoggerdSystemTest.FaultLoggerdSystemTest0010_pre");
773 }
774 std::string filePath = "result";
775 int lines = FaultLoggerdSystemTest::CountLines(filePath);
776 GTEST_LOG_(INFO) << lines;
777 int ret = remove("result");
778 if (ret != 0) {
779 printf("remove failed!");
780 }
781 EXPECT_EQ(lines, 10) << "FaultLoggerdSystemTest0010_pre Failed";
782 GTEST_LOG_(INFO) << "FaultLoggerdSystemTest0010: end.";
783 }
784
785 /**
786 * @tc.name: FaultLoggerdSystemTest0012
787 * @tc.desc: test DumpCatchMultiPid API: multiPid{PID(app),PID(accountmgr)}
788 * @tc.type: FUNC
789 */
790 HWTEST_F (FaultLoggerdSystemTest, FaultLoggerdSystemTest0012, TestSize.Level2)
791 {
792 GTEST_LOG_(INFO) << "FaultLoggerdSystemTest0012: start.";
793 FaultLoggerdSystemTest::StartCrasherLoop(3);
794 int uidSetting = 0;
795 setuid(uidSetting);
796 std::string apply = "accountmgr";
797 int applyPid1 = FaultLoggerdSystemTest::getApplyPid(apply);
798 GTEST_LOG_(INFO) << "applyPid1:" << applyPid1;
799 int applyPid2 = FaultLoggerdSystemTest::loopAppPid;
800 GTEST_LOG_(INFO) << "applyPid2:" << applyPid2;
801 std::vector<int> multiPid {applyPid1, applyPid2};
802 DfxDumpCatcher dumplog;
803 std::string msg = "";
804 bool ret = dumplog.DumpCatchMultiPid(multiPid, msg);
805 GTEST_LOG_(INFO) << ret;
806 GTEST_LOG_(INFO) << msg;
807 string log[] = {"Tid:", "Name:", "Tid:", "Name:crasher_c"};
808 log[0] = log[0] + std::to_string(applyPid1);
809 log[1] = log[1] + apply;
810 log[2] = log[2] + std::to_string(FaultLoggerdSystemTest::loopAppPid);
811 string::size_type idx;
812 int j = 0;
813 int count = 0;
814 for (int i = 0; i < 4; i++) {
815 idx = msg.find(log[j]);
816 GTEST_LOG_(INFO) << log[j];
817 if (idx != string::npos) {
818 count++;
819 }
820 j++;
821 }
822 int expectNum = sizeof(log) / sizeof(log[0]);
823 EXPECT_EQ(count, expectNum) << "FaultLoggerdSystemTest0012 Failed";
824 FaultLoggerdSystemTest::KillCrasherLoopForSomeCase(3);
825 sleep(NUMBER_TWO);
826 GTEST_LOG_(INFO) << "FaultLoggerdSystemTest0012: end.";
827 }
828
829 /**
830 * @tc.name: FaultLoggerdSystemTest0013
831 * @tc.desc: test DumpCatchMultiPid API: multiPid{0,0}
832 * @tc.type: FUNC
833 */
834 HWTEST_F (FaultLoggerdSystemTest, FaultLoggerdSystemTest0013, TestSize.Level2)
835 {
836 GTEST_LOG_(INFO) << "FaultLoggerdSystemTest0013: start.";
837 int applyPid1 = 0;
838 GTEST_LOG_(INFO) << "applyPid1:" << applyPid1;
839 int applyPid2 = 0;
840 GTEST_LOG_(INFO) << "applyPid2:" << applyPid2;
841 std::vector<int> multiPid {applyPid1, applyPid2};
842 DfxDumpCatcher dumplog;
843 std::string msg = "";
844 bool ret = dumplog.DumpCatchMultiPid(multiPid, msg);
845 GTEST_LOG_(INFO) << ret;
846 GTEST_LOG_(INFO) << msg;
847 EXPECT_EQ(ret, false) << "FaultLoggerdSystemTest0013 Failed";
848 GTEST_LOG_(INFO) << "FaultLoggerdSystemTest0013: end.";
849 }
850
851 /**
852 * @tc.name: FaultLoggerdSystemTest0014
853 * @tc.desc: test DumpCatchMultiPid API: multiPid{-11,-11}
854 * @tc.type: FUNC
855 */
856 HWTEST_F (FaultLoggerdSystemTest, FaultLoggerdSystemTest0014, TestSize.Level2)
857 {
858 GTEST_LOG_(INFO) << "FaultLoggerdSystemTest0014: start.";
859 int applyPid1 = -11;
860 GTEST_LOG_(INFO) << "applyPid1:" << applyPid1;
861 int applyPid2 = -11;
862 GTEST_LOG_(INFO) << "applyPid2:" << applyPid2;
863 std::vector<int> multiPid {applyPid1, applyPid2};
864 DfxDumpCatcher dumplog;
865 std::string msg = "";
866 bool ret = dumplog.DumpCatchMultiPid(multiPid, msg);
867 GTEST_LOG_(INFO) << ret;
868 GTEST_LOG_(INFO) << msg;
869 EXPECT_EQ(ret, false) << "FaultLoggerdSystemTest0013 Failed";
870 GTEST_LOG_(INFO) << "FaultLoggerdSystemTest0014: end.";
871 }
872
873 /**
874 * @tc.name: FaultLoggerdSystemTest0015
875 * @tc.desc: test DumpCatchMultiPid API: multiPid{PID(accountmgr),0}
876 * @tc.type: FUNC
877 */
878 HWTEST_F (FaultLoggerdSystemTest, FaultLoggerdSystemTest0015, TestSize.Level2)
879 {
880 GTEST_LOG_(INFO) << "FaultLoggerdSystemTest0015: start.";
881 FaultLoggerdSystemTest::StartCrasherLoop(3);
882 int uidSetting = 0;
883 setuid(uidSetting);
884 std::string apply = "accountmgr";
885 int applyPid1 = FaultLoggerdSystemTest::getApplyPid(apply);
886 GTEST_LOG_(INFO) << "applyPid1:" << applyPid1;
887 int applyPid2 = 0;
888 GTEST_LOG_(INFO) << "applyPid2:" << applyPid2;
889 std::vector<int> multiPid {applyPid1, applyPid2};
890 DfxDumpCatcher dumplog;
891 std::string msg = "";
892 bool ret = dumplog.DumpCatchMultiPid(multiPid, msg);
893 GTEST_LOG_(INFO) << ret;
894 GTEST_LOG_(INFO) << msg;
895 string log[] = { "Tid:", "Name:", "Failed" };
896 log[0] = log[0] + std::to_string(applyPid1);
897 log[1] = log[1] + apply;
898 string::size_type idx;
899 int j = 0;
900 int count = 0;
901 for (int i = 0; i < 3; i++) {
902 idx = msg.find(log[j]);
903 GTEST_LOG_(INFO) << log[j];
904 if (idx != string::npos) {
905 count++;
906 }
907 j++;
908 }
909 int expectNum = sizeof(log) / sizeof(log[0]);
910 EXPECT_EQ(count, expectNum) << "FaultLoggerdSystemTest0015 Failed";
911 FaultLoggerdSystemTest::KillCrasherLoopForSomeCase(3);
912 sleep(NUMBER_TWO);
913 GTEST_LOG_(INFO) << "FaultLoggerdSystemTest0015: end.";
914 }
915
916 /**
917 * @tc.name: FaultLoggerdSystemTest0016
918 * @tc.desc: test DumpCatchMultiPid API: multiPid{PID(accountmgr),PID(app),PID(foundation)}
919 * @tc.type: FUNC
920 */
921 HWTEST_F (FaultLoggerdSystemTest, FaultLoggerdSystemTest0016, TestSize.Level2)
922 {
923 GTEST_LOG_(INFO) << "FaultLoggerdSystemTest0016: start.";
924 FaultLoggerdSystemTest::StartCrasherLoop(3);
925 int uidSetting = 0;
926 setuid(uidSetting);
927 std::string apply1 = "accountmgr";
928 int applyPid1 = FaultLoggerdSystemTest::getApplyPid(apply1);
929 GTEST_LOG_(INFO) << "applyPid1:" << applyPid1;
930 int applyPid2 = FaultLoggerdSystemTest::loopAppPid;
931 GTEST_LOG_(INFO) << "applyPid2:" << applyPid2;
932 std::string apply3 = "foundation";
933 int applyPid3 = FaultLoggerdSystemTest::getApplyPid(apply3);
934 GTEST_LOG_(INFO) << "applyPid3:" << applyPid3;
935 std::vector<int> multiPid {applyPid1, applyPid2, applyPid3};
936 DfxDumpCatcher dumplog;
937 std::string msg = "";
938 bool ret = dumplog.DumpCatchMultiPid(multiPid, msg);
939 GTEST_LOG_(INFO) << ret;
940 GTEST_LOG_(INFO) << msg;
941 string log[] = { "Tid:", "Name:", "Tid:", "Name:crasher_c", "Tid:", "Name:" };
942 log[0] = log[0] + std::to_string(applyPid1);
943 log[1] = log[1] + apply1;
944 log[2] = log[2] + std::to_string(FaultLoggerdSystemTest::loopAppPid);
945 log[4] = log[4] + std::to_string(applyPid3);
946 log[5] = log[5] + apply3;
947 string::size_type idx;
948 int j = 0;
949 int count = 0;
950 for (int i = 0; i < 6; i++) {
951 idx = msg.find(log[j]);
952 GTEST_LOG_(INFO) << log[j];
953 if (idx != string::npos) {
954 count++;
955 }
956 j++;
957 }
958 int expectNum = sizeof(log) / sizeof(log[0]);
959 EXPECT_EQ(count, expectNum) << "FaultLoggerdSystemTest0016 Failed";
960 FaultLoggerdSystemTest::KillCrasherLoopForSomeCase(3);
961 sleep(NUMBER_TWO);
962 GTEST_LOG_(INFO) << "FaultLoggerdSystemTest0016: end.";
963 }
964
965 /**
966 * @tc.name: FaultLoggerdSystemTest0017
967 * @tc.desc: test DumpCatchMultiPid API: multiPid{PID(accountmgr),-11}
968 * @tc.type: FUNC
969 */
970 HWTEST_F (FaultLoggerdSystemTest, FaultLoggerdSystemTest0017, TestSize.Level2)
971 {
972 GTEST_LOG_(INFO) << "FaultLoggerdSystemTest0017: start.";
973 std::string apply = "accountmgr";
974 int applyPid1 = FaultLoggerdSystemTest::getApplyPid(apply);
975 GTEST_LOG_(INFO) << "applyPid1:" << applyPid1;
976 int applyPid2 = -11;
977 GTEST_LOG_(INFO) << "applyPid2:" << applyPid2;
978 std::vector<int> multiPid {applyPid1, applyPid2};
979 DfxDumpCatcher dumplog;
980 std::string msg = "";
981 bool ret = dumplog.DumpCatchMultiPid(multiPid, msg);
982 GTEST_LOG_(INFO) << ret;
983 GTEST_LOG_(INFO) << msg;
984 string log[] = { "Tid:", "Name:", "Failed"};
985 log[0] = log[0] + std::to_string(applyPid1);
986 log[1] = log[1] + apply;
987 string::size_type idx;
988 int j = 0;
989 int count = 0;
990 for (int i = 0; i < 3; i++) {
991 idx = msg.find(log[j]);
992 GTEST_LOG_(INFO) << log[j];
993 if (idx != string::npos) {
994 count++;
995 }
996 j++;
997 }
998 int expectNum = sizeof(log) / sizeof(log[0]);
999 EXPECT_EQ(count, expectNum) << "FaultLoggerdSystemTest0017 Failed";
1000 sleep(NUMBER_TWO);
1001 GTEST_LOG_(INFO) << "FaultLoggerdSystemTest0017: end.";
1002 }
1003
1004 /**
1005 * @tc.name: FaultLoggerdSystemTest0018
1006 * @tc.desc: test DumpCatchMultiPid API: multiPid{9999,9999}
1007 * @tc.type: FUNC
1008 */
1009 HWTEST_F (FaultLoggerdSystemTest, FaultLoggerdSystemTest0018, TestSize.Level2)
1010 {
1011 GTEST_LOG_(INFO) << "FaultLoggerdSystemTest0018: start.";
1012 int uidSetting = 0;
1013 setuid(uidSetting);
1014 int applyPid1 = 9999;
1015 GTEST_LOG_(INFO) << "applyPid1:" << applyPid1;
1016 int applyPid2 = 9999;
1017 GTEST_LOG_(INFO) << "applyPid2:" << applyPid2;
1018 std::vector<int> multiPid {applyPid1, applyPid2};
1019 DfxDumpCatcher dumplog;
1020 std::string msg = "";
1021 bool ret = dumplog.DumpCatchMultiPid(multiPid, msg);
1022 GTEST_LOG_(INFO) << ret;
1023 GTEST_LOG_(INFO) << msg;
1024 EXPECT_EQ(ret, false) << "FaultLoggerdSystemTest0018 Failed";
1025 GTEST_LOG_(INFO) << "FaultLoggerdSystemTest0018: end.";
1026 }
1027
1028 /**
1029 * @tc.name: FaultLoggerdSystemTest0019
1030 * @tc.desc: test DumpCatchMultiPid API: multiPid{PID(accountmgr),9999}
1031 * @tc.type: FUNC
1032 */
1033 HWTEST_F (FaultLoggerdSystemTest, FaultLoggerdSystemTest0019, TestSize.Level2)
1034 {
1035 GTEST_LOG_(INFO) << "FaultLoggerdSystemTest0019: start.";
1036 std::string apply = "accountmgr";
1037 int applyPid1 = FaultLoggerdSystemTest::getApplyPid(apply);
1038 GTEST_LOG_(INFO) << "applyPid1:" << applyPid1;
1039 int applyPid2 = 9999;
1040 GTEST_LOG_(INFO) << "applyPid2:" << applyPid2;
1041 std::vector<int> multiPid {applyPid1, applyPid2};
1042 DfxDumpCatcher dumplog;
1043 std::string msg = "";
1044 bool ret = dumplog.DumpCatchMultiPid(multiPid, msg);
1045 GTEST_LOG_(INFO) << ret;
1046 GTEST_LOG_(INFO) << msg;
1047 string log[] = { "Tid:", "Name:", "Failed"};
1048 log[0] = log[0] + std::to_string(applyPid1);
1049 log[1] = log[1] + apply;
1050 string::size_type idx;
1051 int j = 0;
1052 int count = 0;
1053 for (int i = 0; i < 3; i++) {
1054 idx = msg.find(log[j]);
1055 GTEST_LOG_(INFO) << log[j];
1056 if (idx != string::npos) {
1057 count++;
1058 }
1059 j++;
1060 }
1061 int expectNum = sizeof(log) / sizeof(log[0]);
1062 EXPECT_EQ(count, expectNum) << "FaultLoggerdSystemTest0019 Failed";
1063 sleep(NUMBER_TWO);
1064 GTEST_LOG_(INFO) << "FaultLoggerdSystemTest0019: end.";
1065 }
1066
1067 /**
1068 * @tc.name: FaultLoggerdSystemTest0020
1069 * @tc.desc: test DumpCatchFrame API: PID(test_faul), TID(test_faul)
1070 * @tc.type: FUNC
1071 */
1072 HWTEST_F (FaultLoggerdSystemTest, FaultLoggerdSystemTest0020, TestSize.Level2)
1073 {
1074 GTEST_LOG_(INFO) << "FaultLoggerdSystemTest0020: start.";
1075 std::string apply = "test_faul";
1076 int testPid = FaultLoggerdSystemTest::getApplyPid(apply);
1077 GTEST_LOG_(INFO) << testPid;
1078 DfxDumpCatcher dumplog(getpid());
1079 std::string msg = "";
1080 std::vector<std::shared_ptr<DfxFrame>> frameV;
1081 bool ret = dumplog.InitFrameCatcher();
1082 EXPECT_EQ(ret, true);
1083 ret = dumplog.RequestCatchFrame(gettid());
1084 EXPECT_EQ(ret, true);
1085 ret = dumplog.CatchFrame(gettid(), frameV);
1086 EXPECT_EQ(ret, true);
1087 dumplog.DestroyFrameCatcher();
1088 EXPECT_GT(frameV.size(), 0) << "FaultLoggerdSystemTest0020 Failed";
1089 GTEST_LOG_(INFO) << "FaultLoggerdSystemTest0020: end.";
1090 }
1091
1092 /**
1093 * @tc.name: FaultLoggerdSystemTest0021
1094 * @tc.desc: test DumpCatchFrame API: PID(test_faul), TID(0)
1095 * @tc.type: FUNC
1096 */
1097 HWTEST_F (FaultLoggerdSystemTest, FaultLoggerdSystemTest0021, TestSize.Level2)
1098 {
1099 GTEST_LOG_(INFO) << "FaultLoggerdSystemTest0021: start.";
1100 std::string apply = "test_faul";
1101 int testPid = FaultLoggerdSystemTest::getApplyPid(apply);
1102 GTEST_LOG_(INFO) << testPid;
1103 DfxDumpCatcher dumplog;
1104 std::vector<std::shared_ptr<DfxFrame>> frameV;
1105 bool ret = dumplog.CatchFrame(testPid, frameV);
1106 GTEST_LOG_(INFO) << ret;
1107 EXPECT_EQ(ret, false) << "FaultLoggerdSystemTest0021 Failed";
1108 GTEST_LOG_(INFO) << "FaultLoggerdSystemTest0021: end.";
1109 }
1110
1111 /**
1112 * @tc.name: FaultLoggerdSystemTest0024
1113 * @tc.desc: test DumpCatchFrame API: app PID(-11), TID(test_faul)
1114 * @tc.type: FUNC
1115 */
1116 HWTEST_F (FaultLoggerdSystemTest, FaultLoggerdSystemTest0024, TestSize.Level2)
1117 {
1118 GTEST_LOG_(INFO) << "FaultLoggerdSystemTest0024: start.";
1119 std::string apply = "test_faul";
1120 int testPid = FaultLoggerdSystemTest::getApplyPid(apply);
1121 GTEST_LOG_(INFO) << testPid;
1122 DfxDumpCatcher dumplog;
1123 std::string msg = "";
1124 std::vector<std::shared_ptr<DfxFrame>> frameV;
1125 bool ret = dumplog.CatchFrame(-99, frameV);
1126 GTEST_LOG_(INFO) << ret;
1127 GTEST_LOG_(INFO) << msg;
1128 EXPECT_EQ(ret, false) << "FaultLoggerdSystemTest0024 Failed";
1129 GTEST_LOG_(INFO) << "FaultLoggerdSystemTest0024: end.";
1130 }
1131
1132 /**
1133 * @tc.name: FaultLoggerdSystemTest0025
1134 * @tc.desc: test DumpCatchFrame API: app PID(test_faul), TID(-11)
1135 * @tc.type: FUNC
1136 */
1137 HWTEST_F (FaultLoggerdSystemTest, FaultLoggerdSystemTest0025, TestSize.Level2)
1138 {
1139 GTEST_LOG_(INFO) << "FaultLoggerdSystemTest0025: start.";
1140 std::string apply = "test_faul";
1141 int testPid = FaultLoggerdSystemTest::getApplyPid(apply);
1142 GTEST_LOG_(INFO) << testPid;
1143 DfxDumpCatcher dumplog;
1144 std::string msg = "";
1145 std::vector<std::shared_ptr<DfxFrame>> frameV;
1146 bool ret = dumplog.CatchFrame(-1, frameV);
1147 GTEST_LOG_(INFO) << ret;
1148 GTEST_LOG_(INFO) << msg;
1149 EXPECT_EQ(ret, false) << "FaultLoggerdSystemTest0025 Failed";
1150 GTEST_LOG_(INFO) << "FaultLoggerdSystemTest0025: end.";
1151 }
1152
1153 /**
1154 * @tc.name: FaultLoggerdSystemTest0026
1155 * @tc.desc: test DumpCatchFrame API: app PID(-11), TID(-11)
1156 * @tc.type: FUNC
1157 */
1158 HWTEST_F (FaultLoggerdSystemTest, FaultLoggerdSystemTest0026, TestSize.Level2)
1159 {
1160 GTEST_LOG_(INFO) << "FaultLoggerdSystemTest0026: start.";
1161 DfxDumpCatcher dumplog;
1162 std::string msg = "";
1163 std::vector<std::shared_ptr<DfxFrame>> frameV;
1164 bool ret = dumplog.CatchFrame(-11, frameV);
1165 GTEST_LOG_(INFO) << ret;
1166 GTEST_LOG_(INFO) << msg;
1167 EXPECT_EQ(ret, false) << "FaultLoggerdSystemTest0026 Failed";
1168 GTEST_LOG_(INFO) << "FaultLoggerdSystemTest0026: end.";
1169 }
1170
1171 /**
1172 * @tc.name: FaultLoggerdSystemTest0027
1173 * @tc.desc: test DumpCatchMix API: PID(systemui pid), TID(0)
1174 * @tc.type: FUNC
1175 * @tc.require: issueI5PJ9O
1176 */
1177 HWTEST_F (FaultLoggerdSystemTest, FaultLoggerdSystemTest0027, TestSize.Level2)
1178 {
1179 GTEST_LOG_(INFO) << "FaultLoggerdSystemTest0027: start.";
1180 std::string calcBundleName = "ohos.samples.distributedcalc";
1181 std::string calcAbiltyName = calcBundleName + ".MainAbility";
1182 int calcPid = LaunchTestHap(calcAbiltyName, calcBundleName);
1183 DfxDumpCatcher dumplog;
1184 std::string msg = "";
1185 bool ret = dumplog.DumpCatchMix(calcPid, 0, msg);
1186 GTEST_LOG_(INFO) << ret;
1187 GTEST_LOG_(INFO) << msg;
1188 string log[] = { "Tid:", "comm:ohos.samples.di", "#00", "/system/bin/appspawn",
1189 "comm:DfxWatchdog", "comm:GC_WorkerThread", "comm:ace.bg.1"};
1190 log[0] += std::to_string(calcPid);
1191 string::size_type idx;
1192 int j = 0;
1193 int count = 0;
1194 int expectNum = sizeof(log) / sizeof(log[0]);
1195 for (int i = 0; i < expectNum; i++) {
1196 idx = msg.find(log[j]);
1197 GTEST_LOG_(INFO) << log[j];
1198 if (idx != string::npos) {
1199 count++;
1200 }
1201 j++;
1202 }
1203
1204 EXPECT_EQ(count, expectNum) << "FaultLoggerdSystemTest0027 Failed";
1205 GTEST_LOG_(INFO) << "FaultLoggerdSystemTest0027: end.";
1206 }
1207
1208 /**
1209 * @tc.name: FaultLoggerdSystemTest0028
1210 * @tc.desc: test DumpCatchMix API: PID(systemui pid), TID(systemui pid)
1211 * @tc.type: FUNC
1212 * @tc.require: issueI5PJ9O
1213 */
1214 HWTEST_F (FaultLoggerdSystemTest, FaultLoggerdSystemTest0028, TestSize.Level2)
1215 {
1216 GTEST_LOG_(INFO) << "FaultLoggerdSystemTest0028: start.";
1217 std::string calcBundleName = "ohos.samples.distributedcalc";
1218 std::string calcAbiltyName = calcBundleName + ".MainAbility";
1219 int calcPid = LaunchTestHap(calcAbiltyName, calcBundleName);
1220 DfxDumpCatcher dumplog;
1221 std::string msg = "";
1222 bool ret = dumplog.DumpCatchMix(calcPid, calcPid, msg);
1223 GTEST_LOG_(INFO) << ret;
1224 GTEST_LOG_(INFO) << msg;
1225 string log[] = { "Tid:", "comm:ohos.samples.di", "#00", "/system/bin/appspawn"};
1226 log[0] += std::to_string(calcPid);
1227 string::size_type idx;
1228 int j = 0;
1229 int count = 0;
1230 for (int i = 0; i < 4; i++) {
1231 idx = msg.find(log[j]);
1232 GTEST_LOG_(INFO) << log[j];
1233 if (idx != string::npos) {
1234 count++;
1235 }
1236 j++;
1237 }
1238 int expectNum = sizeof(log) / sizeof(log[0]);
1239 EXPECT_EQ(count, expectNum) << "FaultLoggerdSystemTest0028 Failed";
1240 GTEST_LOG_(INFO) << "FaultLoggerdSystemTest0028: end.";
1241 }
1242
1243 /**
1244 * @tc.name: FaultLoggerdSystemTest0029
1245 * @tc.desc: test DumpCatchMix API: PID(hap pid), TID(-1)
1246 * @tc.type: FUNC
1247 * @tc.require: issueI5PJ9O
1248 */
1249 HWTEST_F (FaultLoggerdSystemTest, FaultLoggerdSystemTest0029, TestSize.Level2)
1250 {
1251 GTEST_LOG_(INFO) << "FaultLoggerdSystemTest0029: start.";
1252 std::string calcBundleName = "ohos.samples.distributedcalc";
1253 std::string calcAbiltyName = calcBundleName + ".MainAbility";
1254 int calcPid = LaunchTestHap(calcAbiltyName, calcBundleName);
1255 DfxDumpCatcher dumplog;
1256 std::string msg = "";
1257 bool ret = dumplog.DumpCatchMix(calcPid, -1, msg);
1258 sleep(2);
1259 GTEST_LOG_(INFO) << ret;
1260 GTEST_LOG_(INFO) << msg;
1261 EXPECT_EQ(ret, false) << "FaultLoggerdSystemTest0029 Failed";
1262 GTEST_LOG_(INFO) << "FaultLoggerdSystemTest0029: end.";
1263 }
1264
1265 /**
1266 * @tc.name: FaultLoggerdSystemTest0030
1267 * @tc.desc: test DumpCatchMix API: PID(-1), TID(-1)
1268 * @tc.type: FUNC
1269 * @tc.require: issueI5PJ9O
1270 */
1271 HWTEST_F (FaultLoggerdSystemTest, FaultLoggerdSystemTest0030, TestSize.Level2)
1272 {
1273 GTEST_LOG_(INFO) << "FaultLoggerdSystemTest0030: start.";
1274 DfxDumpCatcher dumplog;
1275 std::string msg = "";
1276 bool ret = dumplog.DumpCatchMix(-1, -1, msg);
1277 sleep(2);
1278 GTEST_LOG_(INFO) << ret;
1279 GTEST_LOG_(INFO) << msg;
1280 EXPECT_EQ(ret, false) << "FaultLoggerdSystemTest0030 Failed";
1281 GTEST_LOG_(INFO) << "FaultLoggerdSystemTest0030: end.";
1282 }
1283
1284 /**
1285 * @tc.name: FaultLoggerdSystemTest0031
1286 * @tc.desc: test dumpcatcher command: -m -p systemui
1287 * @tc.type: FUNC
1288 * @tc.require: issueI5PJ9O
1289 */
1290 HWTEST_F (FaultLoggerdSystemTest, FaultLoggerdSystemTest0031, TestSize.Level2)
1291 {
1292 GTEST_LOG_(INFO) << "FaultLoggerdSystemTest0031: start.";
1293 std::string calcBundleName = "ohos.samples.distributedcalc";
1294 std::string calcAbiltyName = calcBundleName + ".MainAbility";
1295 int calcPid = LaunchTestHap(calcAbiltyName, calcBundleName);
1296 std::string procCMD = "dumpcatcher -m -p " + std::to_string(calcPid);
1297 string procDumpLog = FaultLoggerdSystemTest::ProcessDumpCommands(procCMD);
1298 GTEST_LOG_(INFO) << "procDumpLog: " << procDumpLog;
1299 int count = 0;
1300 string log[] = { "Tid:", "comm:ohos.samples.di", "#00", "/system/bin/appspawn",
1301 "comm:DfxWatchdog", "comm:GC_WorkerThread", "comm:ace.bg.1"};
1302 log[0] += std::to_string(calcPid);
1303 string::size_type idx;
1304 int expectNum = sizeof(log) / sizeof(log[0]);
1305 for (int i = 0; i < expectNum; i++) {
1306 idx = procDumpLog.find(log[i]);
1307 if (idx != string::npos) {
1308 GTEST_LOG_(INFO) << log[i];
1309 count++;
1310 }
1311 }
1312 EXPECT_EQ(count, expectNum) << "FaultLoggerdSystemTest0031 Failed";
1313 GTEST_LOG_(INFO) << "FaultLoggerdSystemTest0031: end.";
1314 }
1315
1316 /**
1317 * @tc.name: FaultLoggerdSystemTest0032
1318 * @tc.desc: test dumpcatcher command: -m -p systemui tid mainthread
1319 * @tc.type: FUNC
1320 * @tc.require: issueI5PJ9O
1321 */
1322 HWTEST_F (FaultLoggerdSystemTest, FaultLoggerdSystemTest0032, TestSize.Level2)
1323 {
1324 GTEST_LOG_(INFO) << "FaultLoggerdSystemTest0032: start.";
1325 std::string calcBundleName = "ohos.samples.distributedcalc";
1326 std::string calcAbiltyName = calcBundleName + ".MainAbility";
1327 int calcPid = LaunchTestHap(calcAbiltyName, calcBundleName);
1328 std::string procCMD = "dumpcatcher -m -p " + std::to_string(calcPid) +
1329 " -t " + std::to_string(calcPid);
1330 string procDumpLog = FaultLoggerdSystemTest::ProcessDumpCommands(procCMD);
1331 GTEST_LOG_(INFO) << "procDumpLog: " << procDumpLog;
1332 int count = 0;
1333 string log[] = { "Tid:", "comm:ohos.samples.di", "#00", "/system/bin/appspawn"};
1334 log[0] += std::to_string(calcPid);
1335 string::size_type idx;
1336 int expectNum = sizeof(log) / sizeof(log[0]);
1337 for (int i = 0; i < 4; i++) {
1338 idx = procDumpLog.find(log[i]);
1339 if (idx != string::npos) {
1340 GTEST_LOG_(INFO) << log[i];
1341 count++;
1342 }
1343 }
1344 EXPECT_EQ(count, expectNum) << "FaultLoggerdSystemTest0032 Failed";
1345 GTEST_LOG_(INFO) << "FaultLoggerdSystemTest0032: end.";
1346 }
1347
1348 /**
1349 * @tc.name: FaultLoggerdSystemTest0033
1350 * @tc.desc: test dumpcatcher command: -m -p systemui tid -1
1351 * @tc.type: FUNC
1352 * @tc.require: issueI5PJ9O
1353 */
1354 HWTEST_F (FaultLoggerdSystemTest, FaultLoggerdSystemTest0033, TestSize.Level2)
1355 {
1356 GTEST_LOG_(INFO) << "FaultLoggerdSystemTest0033: start.";
1357 std::string systemui = "com.ohos.systemui";
1358 int systemuiPid = FaultLoggerdSystemTest::GetServicePid(systemui);
1359 std::string procCMD = "dumpcatcher -m -p " + std::to_string(systemuiPid) + " -t -1";
1360 string procDumpLog = FaultLoggerdSystemTest::ProcessDumpCommands(procCMD);
1361 GTEST_LOG_(INFO) << "procDumpLog: " << procDumpLog;
1362 int count = 0;
1363 string log[] = {"Failed"};
1364 string::size_type idx;
1365 for (int i = 0; i < 1; i++) {
1366 idx = procDumpLog.find(log[i]);
1367 if (idx != string::npos) {
1368 GTEST_LOG_(INFO) << count;
1369 GTEST_LOG_(INFO) << log[i];
1370 count++;
1371 }
1372 }
1373 EXPECT_EQ(count, 1) << "FaultLoggerdSystemTest0033 Failed";
1374 GTEST_LOG_(INFO) << "FaultLoggerdSystemTest0033: end.";
1375 }
1376
1377 /**
1378 * @tc.name: FaultLoggerdSystemTest0034
1379 * @tc.desc: test dumpcatcher command: -m -p -1 tid -1
1380 * @tc.type: FUNC
1381 * @tc.require: issueI5PJ9O
1382 */
1383 HWTEST_F (FaultLoggerdSystemTest, FaultLoggerdSystemTest0034, TestSize.Level2)
1384 {
1385 GTEST_LOG_(INFO) << "FaultLoggerdSystemTest0034: start.";
1386 std::string systemui = "com.ohos.systemui";
1387 std::string procCMD = "dumpcatcher -m -p -1 -t -1";
1388 string procDumpLog = FaultLoggerdSystemTest::ProcessDumpCommands(procCMD);
1389 GTEST_LOG_(INFO) << "procDumpLog: " << procDumpLog;
1390 int count = 0;
1391 string log[] = {"Failed"};
1392 string::size_type idx;
1393 for (int i = 0; i < 1; i++) {
1394 idx = procDumpLog.find(log[i]);
1395 if (idx != string::npos) {
1396 GTEST_LOG_(INFO) << count;
1397 GTEST_LOG_(INFO) << log[i];
1398 count++;
1399 }
1400 }
1401 EXPECT_EQ(count, 1) << "FaultLoggerdSystemTest0034 Failed";
1402 GTEST_LOG_(INFO) << "FaultLoggerdSystemTest0034: end.";
1403 }
1404
1405 /**
1406 * @tc.name: FaultLoggerdSystemTest0122
1407 * @tc.desc: test C crasher application: StackTop
1408 * @tc.type: FUNC
1409 */
1410 HWTEST_F (FaultLoggerdSystemTest, FaultLoggerdSystemTest0122, TestSize.Level2)
1411 {
1412 GTEST_LOG_(INFO) << "FaultLoggerdSystemTest0122: start.";
1413 std::string cmd = "StackTop";
1414 int cTest = 0;
1415 std::string filePathPid = FaultLoggerdSystemTest::GetfileNamePrefix(cmd, cTest);
1416 GTEST_LOG_(INFO) << "current filePath and pid = \n" << filePathPid;
1417 if (filePathPid.size() < NUMBER_TEN) {
1418 EXPECT_EQ(true, false) << "FaultLoggerdSystemTest0122 Failed";
1419 } else {
1420 char filePath[ARRAY_SIZE_HUNDRED] = { 0, };
1421 char pid[ARRAY_SIZE_HUNDRED] = { 0, };
1422 int res = sscanf_s(filePathPid.c_str(), "%s %s", filePath, sizeof(filePath) - 1, pid, sizeof(pid) - 1);
1423 if (res <= 0) {
1424 GTEST_LOG_(INFO) << "sscanf_s failed.";
1425 }
1426 GTEST_LOG_(INFO) << "current filepath: \n" << filePath;
1427 GTEST_LOG_(INFO) << "current pid: \n" << pid;
1428 std::string filePathStr = filePath;
1429 std::string pidStr = pid;
1430 int ret = FaultLoggerdSystemTest::CheckCountNumStackTop(filePathStr, pidStr, cmd);
1431 GTEST_LOG_(INFO) << "current ret value: \n" << ret;
1432 EXPECT_EQ(ret, 0) << "FaultLoggerdSystemTest0122 Failed";
1433 GTEST_LOG_(INFO) << "FaultLoggerdSystemTest0122: end.";
1434 }
1435 }
1436
1437 /**
1438 * @tc.name: FaultLoggerdSystemTest0123
1439 * @tc.desc: test CPP crasher application: StackTop
1440 * @tc.type: FUNC
1441 */
1442 HWTEST_F (FaultLoggerdSystemTest, FaultLoggerdSystemTest0123, TestSize.Level2)
1443 {
1444 GTEST_LOG_(INFO) << "FaultLoggerdSystemTest0123: start.";
1445 std::string cmd = "StackTop";
1446 int cppTest = 1;
1447 std::string filePathPid = FaultLoggerdSystemTest::GetfileNamePrefix(cmd, cppTest);
1448 GTEST_LOG_(INFO) << "current filePath and pid = \n" << filePathPid;
1449 if (filePathPid.size() < NUMBER_TEN) {
1450 EXPECT_EQ(true, false) << "FaultLoggerdSystemTest0123 Failed";
1451 } else {
1452 char filePath[ARRAY_SIZE_HUNDRED] = { 0, };
1453 char pid[ARRAY_SIZE_HUNDRED] = { 0, };
1454 int res = sscanf_s(filePathPid.c_str(), "%s %s", filePath, sizeof(filePath) - 1, pid, sizeof(pid) - 1);
1455 if (res <= 0) {
1456 GTEST_LOG_(INFO) << "sscanf_s failed.";
1457 }
1458 GTEST_LOG_(INFO) << "current filepath: \n" << filePath;
1459 GTEST_LOG_(INFO) << "current pid: \n" << pid;
1460 std::string filePathStr = filePath;
1461 std::string pidStr = pid;
1462 int ret = FaultLoggerdSystemTest::CheckCountNumStackTop(filePathStr, pidStr, cmd);
1463 GTEST_LOG_(INFO) << "current ret value: \n" << ret;
1464 EXPECT_EQ(ret, 0) << "FaultLoggerdSystemTest0123 Failed";
1465 GTEST_LOG_(INFO) << "FaultLoggerdSystemTest0123: end.";
1466 }
1467 }
1468
1469 /**
1470 * @tc.name: FaultLoggerdSystemTest0001
1471 * @tc.desc: test C crasher application: triSIGILL
1472 * @tc.type: FUNC
1473 */
1474 HWTEST_F (FaultLoggerdSystemTest, FaultLoggerdSystemTest0001, TestSize.Level2)
1475 {
1476 GTEST_LOG_(INFO) << "FaultLoggerdSystemTest0001: start.";
1477 std::string cmd = "triSIGILL";
1478 int cTest = 0;
1479 std::string filePathPid = FaultLoggerdSystemTest::GetfileNamePrefix(cmd, cTest);
1480 if (filePathPid.size() < NUMBER_TEN) {
1481 EXPECT_EQ(true, false) << "ProcessDfxRequestTest0001 Failed";
1482 } else {
1483 GTEST_LOG_(INFO) << "current filePath and pid = \n" << filePathPid;
1484 char filePath[ARRAY_SIZE_HUNDRED];
1485 char pid[ARRAY_SIZE_HUNDRED];
1486 int res = sscanf_s(filePathPid.c_str(), "%s %s", filePath, sizeof(filePath) - 1, pid, sizeof(pid) - 1);
1487 if (res <= 0) {
1488 GTEST_LOG_(INFO) << "sscanf_s failed.";
1489 }
1490 GTEST_LOG_(INFO) << "current filepath: \n" << filePath;
1491 GTEST_LOG_(INFO) << "current pid: \n" << pid;
1492 std::string filePathStr = filePath;
1493 std::string pidStr = pid;
1494 int ret = FaultLoggerdSystemTest::CheckCountNum(filePathStr, pidStr, cmd);
1495 GTEST_LOG_(INFO) << "current ret value: \n" << ret;
1496 EXPECT_EQ(ret, 0) << "ProcessDfxRequestTest0001 Failed";
1497 GTEST_LOG_(INFO) << "FaultLoggerdSystemTest0001: end.";
1498 }
1499 }
1500
1501 /**
1502 * @tc.name: FaultLoggerdSystemTest0002
1503 * @tc.desc: test CPP crasher application: triSIGILL
1504 * @tc.type: FUNC
1505 */
1506 HWTEST_F (FaultLoggerdSystemTest, FaultLoggerdSystemTest0002, TestSize.Level2)
1507 {
1508 GTEST_LOG_(INFO) << "FaultLoggerdSystemTest0002: start.";
1509 std::string cmd = "triSIGILL";
1510 int cppTest = 1;
1511 std::string filePathPid = FaultLoggerdSystemTest::GetfileNamePrefix(cmd, cppTest);
1512 if (filePathPid.size() < NUMBER_TEN) {
1513 EXPECT_EQ(true, false) << "ProcessDfxRequestTest0002 Failed";
1514 } else {
1515 GTEST_LOG_(INFO) << "current filePath and pid = \n" << filePathPid;
1516 char filePath[ARRAY_SIZE_HUNDRED];
1517 char pid[ARRAY_SIZE_HUNDRED];
1518 int res = sscanf_s(filePathPid.c_str(), "%s %s", filePath, sizeof(filePath) - 1, pid, sizeof(pid) - 1);
1519 if (res <= 0) {
1520 GTEST_LOG_(INFO) << "sscanf_s failed.";
1521 }
1522 GTEST_LOG_(INFO) << "current filepath: \n" << filePath;
1523 GTEST_LOG_(INFO) << "current pid: \n" << pid;
1524 std::string filePathStr = filePath;
1525 std::string pidStr = pid;
1526 int ret = FaultLoggerdSystemTest::CheckCountNum(filePathStr, pidStr, cmd);
1527 GTEST_LOG_(INFO) << "current ret value: \n" << ret;
1528 EXPECT_EQ(ret, 0) << "ProcessDfxRequestTest0002 Failed";
1529 GTEST_LOG_(INFO) << "FaultLoggerdSystemTest0002: end.";
1530 }
1531 }
1532
1533 /**
1534 * @tc.name: FaultLoggerdSystemTest0003
1535 * @tc.desc: test C crasher application: triSIGSEGV
1536 * @tc.type: FUNC
1537 */
1538 HWTEST_F (FaultLoggerdSystemTest, FaultLoggerdSystemTest0003, TestSize.Level2)
1539 {
1540 GTEST_LOG_(INFO) << "FaultLoggerdSystemTest0003: start.";
1541 std::string cmd = "triSIGSEGV";
1542 int cTest = 0;
1543 std::string filePathPid = FaultLoggerdSystemTest::GetfileNamePrefix(cmd, cTest);
1544 if (filePathPid.size() < NUMBER_TEN) {
1545 EXPECT_EQ(true, false) << "ProcessDfxRequestTest0003 Failed";
1546 } else {
1547 GTEST_LOG_(INFO) << "current filePath and pid = \n" << filePathPid;
1548 char filePath[ARRAY_SIZE_HUNDRED];
1549 char pid[ARRAY_SIZE_HUNDRED];
1550 int res = sscanf_s(filePathPid.c_str(), "%s %s", filePath, sizeof(filePath) - 1, pid, sizeof(pid) - 1);
1551 if (res <= 0) {
1552 GTEST_LOG_(INFO) << "sscanf_s failed.";
1553 }
1554 GTEST_LOG_(INFO) << "current filepath: \n" << filePath;
1555 GTEST_LOG_(INFO) << "current pid: \n" << pid;
1556 std::string filePathStr = filePath;
1557 std::string pidStr = pid;
1558 int ret = FaultLoggerdSystemTest::CheckCountNum(filePathStr, pidStr, cmd);
1559 GTEST_LOG_(INFO) << "current ret value: \n" << ret;
1560 EXPECT_EQ(ret, 0) << "ProcessDfxRequestTest0003 Failed";
1561 GTEST_LOG_(INFO) << "FaultLoggerdSystemTest0003: end.";
1562 }
1563 }
1564
1565 /**
1566 * @tc.name: FaultLoggerdSystemTest0004
1567 * @tc.desc: test CPP crasher application: triSIGSEGV
1568 * @tc.type: FUNC
1569 */
1570 HWTEST_F (FaultLoggerdSystemTest, FaultLoggerdSystemTest0004, TestSize.Level2)
1571 {
1572 GTEST_LOG_(INFO) << "FaultLoggerdSystemTest0004: start.";
1573 std::string cmd = "triSIGSEGV";
1574 int cppTest = 1;
1575 std::string filePathPid = FaultLoggerdSystemTest::GetfileNamePrefix(cmd, cppTest);
1576 if (filePathPid.size() < NUMBER_TEN) {
1577 EXPECT_EQ(true, false) << "ProcessDfxRequestTest0004 Failed";
1578 } else {
1579 GTEST_LOG_(INFO) << "current filePath and pid = \n" << filePathPid;
1580 char filePath[ARRAY_SIZE_HUNDRED];
1581 char pid[ARRAY_SIZE_HUNDRED];
1582 int res = sscanf_s(filePathPid.c_str(), "%s %s", filePath, sizeof(filePath) - 1, pid, sizeof(pid) - 1);
1583 if (res <= 0) {
1584 GTEST_LOG_(INFO) << "sscanf_s failed.";
1585 }
1586 GTEST_LOG_(INFO) << "current filepath: \n" << filePath;
1587 GTEST_LOG_(INFO) << "current pid: \n" << pid;
1588 std::string filePathStr = filePath;
1589 std::string pidStr = pid;
1590 int ret = FaultLoggerdSystemTest::CheckCountNum(filePathStr, pidStr, cmd);
1591 GTEST_LOG_(INFO) << "current ret value: \n" << ret;
1592 EXPECT_EQ(ret, 0) << "ProcessDfxRequestTest0004 Failed";
1593 GTEST_LOG_(INFO) << "FaultLoggerdSystemTest0004: end.";
1594 }
1595 }
1596
1597 /**
1598 * @tc.name: FaultLoggerdSystemTest0005
1599 * @tc.desc: test C crasher application: triSIGTRAP
1600 * @tc.type: FUNC
1601 */
1602 HWTEST_F (FaultLoggerdSystemTest, FaultLoggerdSystemTest0005, TestSize.Level2)
1603 {
1604 GTEST_LOG_(INFO) << "FaultLoggerdSystemTest0005: start.";
1605 std::string cmd = "triSIGTRAP";
1606 int cTest = 0;
1607 std::string filePathPid = FaultLoggerdSystemTest::GetfileNamePrefix(cmd, cTest);
1608 if (filePathPid.size() < NUMBER_TEN) {
1609 EXPECT_EQ(true, false) << "ProcessDfxRequestTest0005 Failed";
1610 } else {
1611 GTEST_LOG_(INFO) << "current filePath and pid = \n" << filePathPid;
1612 char filePath[ARRAY_SIZE_HUNDRED];
1613 char pid[ARRAY_SIZE_HUNDRED];
1614 int res = sscanf_s(filePathPid.c_str(), "%s %s", filePath, sizeof(filePath) - 1, pid, sizeof(pid) - 1);
1615 if (res <= 0) {
1616 GTEST_LOG_(INFO) << "sscanf_s failed.";
1617 }
1618 GTEST_LOG_(INFO) << "current filepath: \n" << filePath;
1619 GTEST_LOG_(INFO) << "current pid: \n" << pid;
1620 std::string filePathStr = filePath;
1621 std::string pidStr = pid;
1622 int ret = FaultLoggerdSystemTest::CheckCountNum(filePathStr, pidStr, cmd);
1623 GTEST_LOG_(INFO) << "current ret value: \n" << ret;
1624 EXPECT_EQ(ret, 0) << "ProcessDfxRequestTest0005 Failed";
1625 GTEST_LOG_(INFO) << "FaultLoggerdSystemTest0005: end.";
1626 }
1627 }
1628
1629 /**
1630 * @tc.name: FaultLoggerdSystemTest0006
1631 * @tc.desc: test CPP crasher application: triSIGTRAP
1632 * @tc.type: FUNC
1633 */
1634 HWTEST_F (FaultLoggerdSystemTest, FaultLoggerdSystemTest0006, TestSize.Level2)
1635 {
1636 GTEST_LOG_(INFO) << "FaultLoggerdSystemTest0006: start.";
1637 std::string cmd = "triSIGTRAP";
1638 int cppTest = 1;
1639 std::string filePathPid = FaultLoggerdSystemTest::GetfileNamePrefix(cmd, cppTest);
1640 if (filePathPid.size() < NUMBER_TEN) {
1641 EXPECT_EQ(true, false) << "ProcessDfxRequestTest0006 Failed";
1642 } else {
1643 GTEST_LOG_(INFO) << "current filePath and pid = \n" << filePathPid;
1644 char filePath[ARRAY_SIZE_HUNDRED];
1645 char pid[ARRAY_SIZE_HUNDRED];
1646 int res = sscanf_s(filePathPid.c_str(), "%s %s", filePath, sizeof(filePath) - 1, pid, sizeof(pid) - 1);
1647 if (res <= 0) {
1648 GTEST_LOG_(INFO) << "sscanf_s failed.";
1649 }
1650 GTEST_LOG_(INFO) << "current filepath: \n" << filePath;
1651 GTEST_LOG_(INFO) << "current pid: \n" << pid;
1652 std::string filePathStr = filePath;
1653 std::string pidStr = pid;
1654 int ret = FaultLoggerdSystemTest::CheckCountNum(filePathStr, pidStr, cmd);
1655 GTEST_LOG_(INFO) << "current ret value: \n" << ret;
1656 EXPECT_EQ(ret, 0) << "ProcessDfxRequestTest0006 Failed";
1657 GTEST_LOG_(INFO) << "FaultLoggerdSystemTest0006: end.";
1658 }
1659 }
1660
1661 /**
1662 * @tc.name: FaultLoggerdSystemTest0007
1663 * @tc.desc: test C crasher application: triSIGABRT
1664 * @tc.type: FUNC
1665 */
1666 HWTEST_F (FaultLoggerdSystemTest, FaultLoggerdSystemTest0007, TestSize.Level2)
1667 {
1668 GTEST_LOG_(INFO) << "FaultLoggerdSystemTest0007: start.";
1669 std::string cmd = "triSIGABRT";
1670 int cTest = 0;
1671 std::string filePathPid = FaultLoggerdSystemTest::GetfileNamePrefix(cmd, cTest);
1672 if (filePathPid.size() < NUMBER_TEN) {
1673 EXPECT_EQ(true, false) << "ProcessDfxRequestTest0007 Failed";
1674 } else {
1675 GTEST_LOG_(INFO) << "current filePath and pid = \n" << filePathPid;
1676 char filePath[ARRAY_SIZE_HUNDRED];
1677 char pid[ARRAY_SIZE_HUNDRED];
1678 int res = sscanf_s(filePathPid.c_str(), "%s %s", filePath, sizeof(filePath) - 1, pid, sizeof(pid) - 1);
1679 if (res <= 0) {
1680 GTEST_LOG_(INFO) << "sscanf_s failed.";
1681 }
1682 GTEST_LOG_(INFO) << "current filepath: \n" << filePath;
1683 GTEST_LOG_(INFO) << "current pid: \n" << pid;
1684 std::string filePathStr = filePath;
1685 std::string pidStr = pid;
1686 int ret = FaultLoggerdSystemTest::CheckCountNumAbort(filePathStr, pidStr);
1687 GTEST_LOG_(INFO) << "current ret value: \n" << ret;
1688 EXPECT_EQ(ret, 0) << "ProcessDfxRequestTest0007 Failed";
1689 GTEST_LOG_(INFO) << "FaultLoggerdSystemTest0007: end.";
1690 }
1691 }
1692
1693 /**
1694 * @tc.name: FaultLoggerdSystemTest0008
1695 * @tc.desc: test CPP crasher application: triSIGABRT
1696 * @tc.type: FUNC
1697 */
1698 HWTEST_F (FaultLoggerdSystemTest, FaultLoggerdSystemTest0008, TestSize.Level2)
1699 {
1700 GTEST_LOG_(INFO) << "FaultLoggerdSystemTest0008: start.";
1701 std::string cmd = "triSIGABRT";
1702 int cppTest = 1;
1703 std::string filePathPid = FaultLoggerdSystemTest::GetfileNamePrefix(cmd, cppTest);
1704 if (filePathPid.size() < NUMBER_TEN) {
1705 EXPECT_EQ(true, false) << "ProcessDfxRequestTest0008 Failed";
1706 } else {
1707 GTEST_LOG_(INFO) << "current filePath and pid = \n" << filePathPid;
1708 char filePath[ARRAY_SIZE_HUNDRED];
1709 char pid[ARRAY_SIZE_HUNDRED];
1710 int res = sscanf_s(filePathPid.c_str(), "%s %s", filePath, sizeof(filePath) - 1, pid, sizeof(pid) - 1);
1711 if (res <= 0) {
1712 GTEST_LOG_(INFO) << "sscanf_s failed.";
1713 }
1714 GTEST_LOG_(INFO) << "current filepath: \n" << filePath;
1715 GTEST_LOG_(INFO) << "current pid: \n" << pid;
1716 std::string filePathStr = filePath;
1717 std::string pidStr = pid;
1718 int ret = FaultLoggerdSystemTest::CheckCountNumAbort(filePathStr, pidStr);
1719 GTEST_LOG_(INFO) << "current ret value: \n" << ret;
1720 EXPECT_EQ(ret, 0) << "ProcessDfxRequestTest0008 Failed";
1721 GTEST_LOG_(INFO) << "FaultLoggerdSystemTest0008: end.";
1722 }
1723 }
1724
1725 /**
1726 * @tc.name: FaultLoggerdSystemTest0009
1727 * @tc.desc: test C crasher application: 50 Abnormal signal
1728 * @tc.type: FUNC
1729 */
1730 HWTEST_F (FaultLoggerdSystemTest, FaultLoggerdSystemTest0009, TestSize.Level2)
1731 {
1732 GTEST_LOG_(INFO) << "FaultLoggerdSystemTest0009: start.";
1733 std::string rmFiles = "rm -rf /data/log/faultlog/temp/*";
1734 system(rmFiles.c_str());
1735 int i;
1736 for (i = 0; i < 50; i++) {
1737 system("/data/crasher_c CrashTest &");
1738 }
1739
1740 int sleepSecond = 10;
1741 sleep(sleepSecond);
1742 if (i == 50) {
1743 std::vector<std::string> files;
1744 OHOS::GetDirFiles("/data/log/faultlog/temp/", files);
1745 GTEST_LOG_(INFO) << files.size();
1746 if (files.size() == 50) {
1747 GTEST_LOG_(INFO) << "FaultLoggerdSystemTest0009: end.";
1748 }
1749 } else {
1750 EXPECT_EQ(0, 1) << "FaultLoggerdSystemTest0009 Failed";
1751 }
1752 }
1753
1754 /**
1755 * @tc.name: FaultLoggerdSystemTest001
1756 * @tc.desc: test C crasher application: SIGFPE
1757 * @tc.type: FUNC
1758 */
1759 HWTEST_F (FaultLoggerdSystemTest, FaultLoggerdSystemTest001, TestSize.Level2)
1760 {
1761 GTEST_LOG_(INFO) << "FaultLoggerdSystemTest001: start.";
1762
1763 std::string cmd = "SIGFPE";
1764 int cTest = 0;
1765 std::string filePathPid = FaultLoggerdSystemTest::GetfileNamePrefix(cmd, cTest);
1766 if (filePathPid.size() < NUMBER_TEN) {
1767 EXPECT_EQ(true, false) << "ProcessDfxRequestTest001 Failed";
1768 } else {
1769 GTEST_LOG_(INFO) << "current filePath and pid = \n" << filePathPid;
1770
1771 char filePath[ARRAY_SIZE_HUNDRED] = { 0, };
1772 char pid[ARRAY_SIZE_HUNDRED] = { 0, };
1773 int res = sscanf_s(filePathPid.c_str(), "%s %s", filePath, sizeof(filePath) - 1, pid, sizeof(pid) - 1);
1774 if (res <= 0) {
1775 GTEST_LOG_(INFO) << "sscanf_s failed.";
1776 }
1777 GTEST_LOG_(INFO) << "current filepath: \n" << filePath;
1778 GTEST_LOG_(INFO) << "current pid: \n" << pid;
1779
1780 std::string filePathStr = filePath;
1781 std::string pidStr = pid;
1782 int ret = FaultLoggerdSystemTest::CheckCountNum(filePathStr, pidStr, cmd);
1783 GTEST_LOG_(INFO) << "current ret value: \n" << ret;
1784
1785 EXPECT_EQ(ret, 0) << "ProcessDfxRequestTest001 Failed";
1786
1787 GTEST_LOG_(INFO) << "FaultLoggerdSystemTest001: end.";
1788 }
1789 }
1790
1791 /**
1792 * @tc.name: FaultLoggerdSystemTest001_level0
1793 * @tc.desc: test C crasher application: SIGFPE
1794 * @tc.type: FUNC
1795 */
1796 HWTEST_F (FaultLoggerdSystemTest, FaultLoggerdSystemTest001_level0, TestSize.Level0)
1797 {
1798 GTEST_LOG_(INFO) << "FaultLoggerdSystemTest001_level0: start.";
1799
1800 std::string cmd = "SIGFPE";
1801 int cTest = 0;
1802 std::string filePathPid = FaultLoggerdSystemTest::GetfileNamePrefix(cmd, cTest);
1803 if (filePathPid.size() < NUMBER_TEN) {
1804 EXPECT_EQ(true, false) << "FaultLoggerdSystemTest001_level0 Failed";
1805 } else {
1806 GTEST_LOG_(INFO) << "current filePath and pid = \n" << filePathPid;
1807
1808 char filePath[ARRAY_SIZE_HUNDRED] = { 0, };
1809 char pid[ARRAY_SIZE_HUNDRED] = { 0, };
1810 int res = sscanf_s(filePathPid.c_str(), "%s %s", filePath, sizeof(filePath) - 1, pid, sizeof(pid) - 1);
1811 if (res <= 0) {
1812 GTEST_LOG_(INFO) << "sscanf_s failed.";
1813 }
1814 GTEST_LOG_(INFO) << "current filepath: \n" << filePath;
1815 GTEST_LOG_(INFO) << "current pid: \n" << pid;
1816
1817 std::string filePathStr = filePath;
1818 std::string pidStr = pid;
1819 int ret = FaultLoggerdSystemTest::CheckCountNum(filePathStr, pidStr, cmd);
1820 GTEST_LOG_(INFO) << "current ret value: \n" << ret;
1821
1822 EXPECT_EQ(ret, 0) << "FaultLoggerdSystemTest001_level0 Failed";
1823
1824 GTEST_LOG_(INFO) << "FaultLoggerdSystemTest001_level0: end.";
1825 }
1826 }
1827
1828 /**
1829 * @tc.name: FaultLoggerdSystemTest002
1830 * @tc.desc: test C crasher application: SIGILL
1831 * @tc.type: FUNC
1832 */
1833 HWTEST_F (FaultLoggerdSystemTest, FaultLoggerdSystemTest002, TestSize.Level2)
1834 {
1835
1836 GTEST_LOG_(INFO) << "FaultLoggerdSystemTest002: start.";
1837
1838 std::string cmd = "SIGILL";
1839 int cTest = 0;
1840 std::string filePathPid = FaultLoggerdSystemTest::GetfileNamePrefix(cmd, cTest);
1841 if (filePathPid.size() < NUMBER_TEN) {
1842 EXPECT_EQ(true, false) << "ProcessDfxRequestTest002 Failed";
1843 } else {
1844 GTEST_LOG_(INFO) << "current filePath and pid = \n" << filePathPid;
1845
1846 char filePath[ARRAY_SIZE_HUNDRED] = { 0, };
1847 char pid[ARRAY_SIZE_HUNDRED] = { 0, };
1848 int res = sscanf_s(filePathPid.c_str(), "%s %s", filePath, sizeof(filePath) - 1, pid, sizeof(pid) - 1);
1849 if (res <= 0) {
1850 GTEST_LOG_(INFO) << "sscanf_s failed.";
1851 }
1852 GTEST_LOG_(INFO) << "current filepath: \n" << filePath;
1853 GTEST_LOG_(INFO) << "current pid: \n" << pid;
1854
1855 std::string filePathStr = filePath;
1856 std::string pidStr = pid;
1857 int ret = FaultLoggerdSystemTest::CheckCountNum(filePathStr, pidStr, cmd);
1858 GTEST_LOG_(INFO) << "current ret value: \n" << ret;
1859
1860 EXPECT_EQ(ret, 0) << "ProcessDfxRequestTest002 Failed";
1861 GTEST_LOG_(INFO) << "FaultLoggerdSystemTest002: end.";
1862 }
1863 }
1864
1865 /**
1866 * @tc.name: FaultLoggerdSystemTest003
1867 * @tc.desc: test C crasher application: SIGSEGV
1868 * @tc.type: FUNC
1869 */
1870 HWTEST_F (FaultLoggerdSystemTest, FaultLoggerdSystemTest003, TestSize.Level2)
1871 {
1872
1873 GTEST_LOG_(INFO) << "FaultLoggerdSystemTest003: start.";
1874
1875 std::string cmd = "SIGSEGV";
1876 int cTest = 0;
1877 std::string filePathPid = FaultLoggerdSystemTest::GetfileNamePrefix(cmd, cTest);
1878 if (filePathPid.size() < NUMBER_TEN) {
1879 EXPECT_EQ(true, false) << "ProcessDfxRequestTest003 Failed";
1880 } else {
1881 GTEST_LOG_(INFO) << "current filePath and pid = \n" << filePathPid;
1882
1883 char filePath[ARRAY_SIZE_HUNDRED] = { 0, };
1884 char pid[ARRAY_SIZE_HUNDRED] = { 0, };
1885 int res = sscanf_s(filePathPid.c_str(), "%s %s", filePath, sizeof(filePath) - 1, pid, sizeof(pid) - 1);
1886 if (res <= 0) {
1887 GTEST_LOG_(INFO) << "sscanf_s failed.";
1888 }
1889 GTEST_LOG_(INFO) << "current filepath: \n" << filePath;
1890 GTEST_LOG_(INFO) << "current pid: \n" << pid;
1891
1892 std::string filePathStr = filePath;
1893 std::string pidStr = pid;
1894 int ret = FaultLoggerdSystemTest::CheckCountNum(filePathStr, pidStr, cmd);
1895 GTEST_LOG_(INFO) << "current ret value: \n" << ret;
1896 EXPECT_EQ(ret, 0) << "ProcessDfxRequestTest003 Failed";
1897 GTEST_LOG_(INFO) << "FaultLoggerdSystemTest003: end.";
1898 }
1899 }
1900
1901 /**
1902 * @tc.name: FaultLoggerdSystemTest004
1903 * @tc.desc: test C crasher application: SIGTRAP
1904 * @tc.type: FUNC
1905 */
1906 HWTEST_F (FaultLoggerdSystemTest, FaultLoggerdSystemTest004, TestSize.Level2)
1907 {
1908 GTEST_LOG_(INFO) << "FaultLoggerdSystemTest004: start.";
1909 std::string cmd = "SIGTRAP";
1910 int cTest = 0;
1911 std::string filePathPid = FaultLoggerdSystemTest::GetfileNamePrefix(cmd, cTest);
1912 if (filePathPid.size() < NUMBER_TEN) {
1913 EXPECT_EQ(true, false) << "ProcessDfxRequestTest004 Failed";
1914 } else {
1915 GTEST_LOG_(INFO) << "current filePath and pid = \n" << filePathPid;
1916 char filePath[ARRAY_SIZE_HUNDRED] = { 0, };
1917 char pid[ARRAY_SIZE_HUNDRED] = { 0, };
1918 int res = sscanf_s(filePathPid.c_str(), "%s %s", filePath, sizeof(filePath) - 1, pid, sizeof(pid) - 1);
1919 if (res <= 0) {
1920 GTEST_LOG_(INFO) << "sscanf_s failed.";
1921 }
1922 GTEST_LOG_(INFO) << "current filepath: \n" << filePath;
1923 GTEST_LOG_(INFO) << "current pid: \n" << pid;
1924
1925 std::string filePathStr = filePath;
1926 std::string pidStr = pid;
1927 int ret = FaultLoggerdSystemTest::CheckCountNum(filePathStr, pidStr, cmd);
1928 GTEST_LOG_(INFO) << "current ret value: \n" << ret;
1929 bool testResult = false;
1930 if (ret == 0) {
1931 testResult = true;
1932 }
1933 EXPECT_EQ(true, testResult) << "ProcessDfxRequestTest004 Failed";
1934 GTEST_LOG_(INFO) << "FaultLoggerdSystemTest004: end.";
1935 }
1936 }
1937
1938 /**
1939 * @tc.name: FaultLoggerdSystemTest005
1940 * @tc.desc: test C crasher application: SIGABRT
1941 * @tc.type: FUNC
1942 */
1943 HWTEST_F (FaultLoggerdSystemTest, FaultLoggerdSystemTest005, TestSize.Level2)
1944 {
1945 GTEST_LOG_(INFO) << "FaultLoggerdSystemTest005: start.";
1946 std::string cmd = "SIGABRT";
1947 int cTest = 0;
1948 std::string filePathPid = FaultLoggerdSystemTest::GetfileNamePrefix(cmd, cTest);
1949 GTEST_LOG_(INFO) << "current filePath and pid = \n" << filePathPid;
1950 if (filePathPid.size() < NUMBER_TEN) {
1951 EXPECT_EQ(true, false) << "ProcessDfxRequestTest005 Failed";
1952 } else {
1953 char filePath[ARRAY_SIZE_HUNDRED] = { 0, };
1954 char pid[ARRAY_SIZE_HUNDRED] = { 0, };
1955 int res = sscanf_s(filePathPid.c_str(), "%s %s", filePath, sizeof(filePath) - 1, pid, sizeof(pid) - 1);
1956 if (res <= 0) {
1957 GTEST_LOG_(INFO) << "sscanf_s failed.";
1958 }
1959 GTEST_LOG_(INFO) << "current filepath: \n" << filePath;
1960 GTEST_LOG_(INFO) << "current pid: \n" << pid;
1961
1962 std::string filePathStr = filePath;
1963 std::string pidStr = pid;
1964 int ret = FaultLoggerdSystemTest::CheckCountNumAbort(filePathStr, pidStr);
1965 GTEST_LOG_(INFO) << "current ret value: \n" << ret;
1966
1967 EXPECT_EQ(ret, 0) << "ProcessDfxRequestTest005 Failed";
1968 GTEST_LOG_(INFO) << "FaultLoggerdSystemTest005: end.";
1969 }
1970 }
1971
1972 /**
1973 * @tc.name: FaultLoggerdSystemTest006
1974 * @tc.desc: test C crasher application: SIGBUS
1975 * @tc.type: FUNC
1976 */
1977 HWTEST_F (FaultLoggerdSystemTest, FaultLoggerdSystemTest006, TestSize.Level2)
1978 {
1979 GTEST_LOG_(INFO) << "FaultLoggerdSystemTest006: start.";
1980 std::string cmd = "SIGBUS";
1981 int cTest = 0;
1982 std::string filePathPid = FaultLoggerdSystemTest::GetfileNamePrefix(cmd, cTest);
1983 GTEST_LOG_(INFO) << "current filePath and pid = \n" << filePathPid;
1984 if (filePathPid.size() < NUMBER_TEN) {
1985 EXPECT_EQ(true, false) << "ProcessDfxRequestTest006 Failed";
1986 } else {
1987 char filePath[ARRAY_SIZE_HUNDRED] = { 0, };
1988 char pid[ARRAY_SIZE_HUNDRED] = { 0, };
1989 int res = sscanf_s(filePathPid.c_str(), "%s %s", filePath, sizeof(filePath) - 1, pid, sizeof(pid) - 1);
1990 if (res <= 0) {
1991 GTEST_LOG_(INFO) << "sscanf_s failed.";
1992 }
1993 GTEST_LOG_(INFO) << "current filepath: \n" << filePath;
1994 GTEST_LOG_(INFO) << "current pid: \n" << pid;
1995 std::string filePathStr = filePath;
1996 std::string pidStr = pid;
1997 int ret = FaultLoggerdSystemTest::CheckCountNum(filePathStr, pidStr, cmd);
1998 GTEST_LOG_(INFO) << "current ret value: \n" << ret;
1999
2000 EXPECT_EQ(ret, 0) << "ProcessDfxRequestTest006 Failed";
2001 GTEST_LOG_(INFO) << "FaultLoggerdSystemTest006: end.";
2002 }
2003 }
2004
2005 /**
2006 * @tc.name: FaultLoggerdSystemTest007
2007 * @tc.desc: test C crasher application: STACKTRACE
2008 * @tc.type: FUNC
2009 */
2010 HWTEST_F (FaultLoggerdSystemTest, FaultLoggerdSystemTest007, TestSize.Level2)
2011 {
2012 GTEST_LOG_(INFO) << "FaultLoggerdSystemTest007: start.";
2013 std::string cmd = "STACKTRACE";
2014 GTEST_LOG_(INFO) << "FaultLoggerdSystemTest007: end.";
2015 }
2016
2017 /**
2018 * @tc.name: FaultLoggerdSystemTest008
2019 * @tc.desc: test C crasher application: triSIGTRAP
2020 * @tc.type: FUNC
2021 */
2022 HWTEST_F (FaultLoggerdSystemTest, FaultLoggerdSystemTest008, TestSize.Level2)
2023 {
2024 GTEST_LOG_(INFO) << "FaultLoggerdSystemTest008: start.";
2025 std::string cmd = "triSIGTRAP";
2026 int cTest = 0;
2027 std::string filePathPid = FaultLoggerdSystemTest::GetfileNamePrefix(cmd, cTest);
2028 if (filePathPid.size() < NUMBER_TEN) {
2029 EXPECT_EQ(true, false) << "ProcessDfxRequestTest008 Failed";
2030 } else {
2031 GTEST_LOG_(INFO) << "current filePath and pid = \n" << filePathPid;
2032 char filePath[ARRAY_SIZE_HUNDRED] = { 0, };
2033 char pid[ARRAY_SIZE_HUNDRED] = { 0, };
2034 int res = sscanf_s(filePathPid.c_str(), "%s %s", filePath, sizeof(filePath) - 1, pid, sizeof(pid) - 1);
2035 if (res <= 0) {
2036 GTEST_LOG_(INFO) << "sscanf_s failed.";
2037 }
2038 GTEST_LOG_(INFO) << "current filepath: \n" << filePath;
2039 GTEST_LOG_(INFO) << "current pid: \n" << pid;
2040 std::string filePathStr = filePath;
2041 std::string pidStr = pid;
2042 int ret = FaultLoggerdSystemTest::CheckCountNum(filePathStr, pidStr, cmd);
2043
2044 GTEST_LOG_(INFO) << "current ret value: \n" << ret;
2045 EXPECT_EQ(ret, 0) << "ProcessDfxRequestTest008 Failed";
2046 GTEST_LOG_(INFO) << "FaultLoggerdSystemTest008: end.";
2047 }
2048 }
2049
2050 /**
2051 * @tc.name: FaultLoggerdSystemTest009
2052 * @tc.desc: test C crasher application: triSIGSEGV
2053 * @tc.type: FUNC
2054 */
2055 HWTEST_F (FaultLoggerdSystemTest, FaultLoggerdSystemTest009, TestSize.Level2)
2056 {
2057
2058 GTEST_LOG_(INFO) << "FaultLoggerdSystemTest009: start.";
2059
2060 std::string cmd = "triSIGSEGV";
2061 int cTest = 0;
2062 std::string filePathPid = FaultLoggerdSystemTest::GetfileNamePrefix(cmd, cTest);
2063 if (filePathPid.size() < NUMBER_TEN) {
2064 EXPECT_EQ(true, false) << "ProcessDfxRequestTest009 Failed";
2065 } else {
2066 GTEST_LOG_(INFO) << "current filePath and pid = \n" << filePathPid;
2067
2068 char filePath[ARRAY_SIZE_HUNDRED] = { 0, };
2069 char pid[ARRAY_SIZE_HUNDRED] = { 0, };
2070 int res = sscanf_s(filePathPid.c_str(), "%s %s", filePath, sizeof(filePath) - 1, pid, sizeof(pid) - 1);
2071 if (res <= 0) {
2072 GTEST_LOG_(INFO) << "sscanf_s failed.";
2073 }
2074 GTEST_LOG_(INFO) << "current filepath: \n" << filePath;
2075 GTEST_LOG_(INFO) << "current pid: \n" << pid;
2076
2077 std::string filePathStr = filePath;
2078 std::string pidStr = pid;
2079 int ret = FaultLoggerdSystemTest::CheckCountNum(filePathStr, pidStr, cmd);
2080
2081 GTEST_LOG_(INFO) << "current ret value: \n" << ret;
2082
2083 EXPECT_EQ(ret, 0) << "ProcessDfxRequestTest009 Failed";
2084 GTEST_LOG_(INFO) << "FaultLoggerdSystemTest009: end.";
2085 }
2086 }
2087
2088 /**
2089 * @tc.name: FaultLoggerdSystemTest010
2090 * @tc.desc: test C crasher application: MaxStack
2091 * @tc.type: FUNC
2092 */
2093 HWTEST_F (FaultLoggerdSystemTest, FaultLoggerdSystemTest010, TestSize.Level2)
2094 {
2095 GTEST_LOG_(INFO) << "FaultLoggerdSystemTest010: start.";
2096 std::string cmd = "MaxStack";
2097 int cTest = 0;
2098 std::string filePathPid = FaultLoggerdSystemTest::GetfileNamePrefix(cmd, cTest);
2099 if (filePathPid.size() < NUMBER_TEN) {
2100 EXPECT_EQ(true, false) << "ProcessDfxRequestTest010 Failed";
2101 } else {
2102 GTEST_LOG_(INFO) << "current filePath and pid = \n" << filePathPid;
2103 char filePath[ARRAY_SIZE_HUNDRED] = { 0, };
2104 char pid[ARRAY_SIZE_HUNDRED] = { 0, };
2105 int res = sscanf_s(filePathPid.c_str(), "%s %s", filePath, sizeof(filePath) - 1, pid, sizeof(pid) - 1);
2106 if (res <= 0) {
2107 GTEST_LOG_(INFO) << "sscanf_s failed.";
2108 }
2109 GTEST_LOG_(INFO) << "current filepath: \n" << filePath;
2110 GTEST_LOG_(INFO) << "current pid: \n" << pid;
2111 std::string filePathStr = filePath;
2112 std::string pidStr = pid;
2113 int ret = FaultLoggerdSystemTest::CheckCountNum(filePathStr, pidStr, cmd);
2114
2115 GTEST_LOG_(INFO) << "current ret value: \n" << ret;
2116 EXPECT_EQ(ret, 0) << "ProcessDfxRequestTest010 Failed";
2117 GTEST_LOG_(INFO) << "FaultLoggerdSystemTest010: end.";
2118 }
2119 }
2120
2121 /**
2122 * @tc.name: FaultLoggerdSystemTest011
2123 * @tc.desc: test C crasher application: MaxMethod
2124 * @tc.type: FUNC
2125 */
2126 HWTEST_F (FaultLoggerdSystemTest, FaultLoggerdSystemTest011, TestSize.Level2)
2127 {
2128 GTEST_LOG_(INFO) << "FaultLoggerdSystemTest011: start.";
2129 std::string cmd = "MaxMethod";
2130 int cTest = 0;
2131 std::string filePathPid = FaultLoggerdSystemTest::GetfileNamePrefix(cmd, cTest);
2132 if (filePathPid.size() < NUMBER_TEN) {
2133 EXPECT_EQ(true, false) << "ProcessDfxRequestTest011 Failed";
2134 } else {
2135 GTEST_LOG_(INFO) << "current filePath and pid = \n" << filePathPid;
2136 char filePath[ARRAY_SIZE_HUNDRED] = { 0, };
2137 char pid[ARRAY_SIZE_HUNDRED] = { 0, };
2138 int res = sscanf_s(filePathPid.c_str(), "%s %s", filePath, sizeof(filePath) - 1, pid, sizeof(pid) - 1);
2139 if (res <= 0) {
2140 GTEST_LOG_(INFO) << "sscanf_s failed.";
2141 }
2142 GTEST_LOG_(INFO) << "current filepath: \n" << filePath;
2143 GTEST_LOG_(INFO) << "current pid: \n" << pid;
2144 std::string filePathStr = filePath;
2145 std::string pidStr = pid;
2146 int ret = FaultLoggerdSystemTest::CheckCountNum(filePathStr, pidStr, cmd);
2147
2148 GTEST_LOG_(INFO) << "current ret value: \n" << ret;
2149 EXPECT_EQ(ret, 0) << "ProcessDfxRequestTest011 Failed";
2150 GTEST_LOG_(INFO) << "FaultLoggerdSystemTest011: end.";
2151 }
2152 }
2153
2154
2155
2156 /**
2157 * @tc.name: FaultLoggerdSystemTest013
2158 * @tc.desc: test CPP crasher application: SIGFPE
2159 * @tc.type: FUNC
2160 */
2161 HWTEST_F (FaultLoggerdSystemTest, FaultLoggerdSystemTest013, TestSize.Level2)
2162 {
2163 GTEST_LOG_(INFO) << "FaultLoggerdSystemTest013: start.";
2164 std::string cmd = "SIGFPE";
2165 int cppTest = 1;
2166 string filePathPid = FaultLoggerdSystemTest::GetfileNamePrefix(cmd, cppTest);
2167 if (filePathPid.size() < NUMBER_TEN) {
2168 EXPECT_EQ(true, false) << "ProcessDfxRequestTest013 Failed";
2169 } else {
2170 GTEST_LOG_(INFO) << "current filePath and pid = \n" << filePathPid;
2171 char filePath[ARRAY_SIZE_HUNDRED] = { 0, };
2172 char pid[ARRAY_SIZE_HUNDRED] = { 0, };
2173 int res = sscanf_s(filePathPid.c_str(), "%s %s", filePath, sizeof(filePath) - 1, pid, sizeof(pid) - 1);
2174 if (res <= 0) {
2175 GTEST_LOG_(INFO) << "sscanf_s failed.";
2176 }
2177 GTEST_LOG_(INFO) << "current filepath: \n" << filePath;
2178 GTEST_LOG_(INFO) << "current pid: \n" << pid;
2179 std::string filePathStr = filePath;
2180 std::string pidStr = pid;
2181 int ret = FaultLoggerdSystemTest::CheckCountNum(filePathStr, pidStr, cmd);
2182 GTEST_LOG_(INFO) << "current ret value: \n" << ret;
2183 EXPECT_EQ(ret, 0) << "ProcessDfxRequestTest013 Failed";
2184 GTEST_LOG_(INFO) << "FaultLoggerdSystemTest013: end.";
2185 }
2186 }
2187
2188 /**
2189 * @tc.name: FaultLoggerdSystemTest014
2190 * @tc.desc: test CPP crasher application: SIGILL
2191 * @tc.type: FUNC
2192 */
2193 HWTEST_F (FaultLoggerdSystemTest, FaultLoggerdSystemTest014, TestSize.Level2)
2194 {
2195 GTEST_LOG_(INFO) << "FaultLoggerdSystemTest014: start.";
2196 std::string cmd = "SIGILL";
2197 int cppTest = 1;
2198 string filePathPid = FaultLoggerdSystemTest::GetfileNamePrefix(cmd, cppTest);
2199 if (filePathPid.size() < NUMBER_TEN) {
2200 EXPECT_EQ(true, false) << "ProcessDfxRequestTest014 Failed";
2201 } else {
2202 GTEST_LOG_(INFO) << "current filePath and pid = \n" << filePathPid;
2203 char filePath[ARRAY_SIZE_HUNDRED] = { 0, };
2204 char pid[ARRAY_SIZE_HUNDRED] = { 0, };
2205 int res = sscanf_s(filePathPid.c_str(), "%s %s", filePath, sizeof(filePath) - 1, pid, sizeof(pid) - 1);
2206 if (res <= 0) {
2207 GTEST_LOG_(INFO) << "sscanf_s failed.";
2208 }
2209 GTEST_LOG_(INFO) << "current filepath: \n" << filePath;
2210 GTEST_LOG_(INFO) << "current pid: \n" << pid;
2211 std::string filePathStr = filePath;
2212 std::string pidStr = pid;
2213 int ret = FaultLoggerdSystemTest::CheckCountNum(filePathStr, pidStr, cmd);
2214
2215 GTEST_LOG_(INFO) << "current ret value: \n" << ret;
2216 EXPECT_EQ(ret, 0) << "ProcessDfxRequestTest014 Failed";
2217 GTEST_LOG_(INFO) << "FaultLoggerdSystemTest014: end.";
2218 }
2219 }
2220
2221 /**
2222 * @tc.name: FaultLoggerdSystemTest015
2223 * @tc.desc: test CPP crasher application: SIGSEGV
2224 * @tc.type: FUNC
2225 */
2226 HWTEST_F (FaultLoggerdSystemTest, FaultLoggerdSystemTest015, TestSize.Level2)
2227 {
2228 GTEST_LOG_(INFO) << "FaultLoggerdSystemTest015: start.";
2229 std::string cmd = "SIGSEGV";
2230 int cppTest = 1;
2231 string filePathPid = FaultLoggerdSystemTest::GetfileNamePrefix(cmd, cppTest);
2232 if (filePathPid.size() < NUMBER_TEN) {
2233 EXPECT_EQ(true, false) << "ProcessDfxRequestTest015 Failed";
2234 } else {
2235 GTEST_LOG_(INFO) << "current filePath and pid = \n" << filePathPid;
2236 char filePath[ARRAY_SIZE_HUNDRED] = { 0, };
2237 char pid[ARRAY_SIZE_HUNDRED] = { 0, };
2238 int res = sscanf_s(filePathPid.c_str(), "%s %s", filePath, sizeof(filePath) - 1, pid, sizeof(pid) - 1);
2239 if (res <= 0) {
2240 GTEST_LOG_(INFO) << "sscanf_s failed.";
2241 }
2242 GTEST_LOG_(INFO) << "current filepath: \n" << filePath;
2243 GTEST_LOG_(INFO) << "current pid: \n" << pid;
2244 std::string filePathStr = filePath;
2245 std::string pidStr = pid;
2246 int ret = FaultLoggerdSystemTest::CheckCountNum(filePathStr, pidStr, cmd);
2247
2248 GTEST_LOG_(INFO) << "current ret value: \n" << ret;
2249 EXPECT_EQ(ret, 0) << "ProcessDfxRequestTest015 Failed";
2250 GTEST_LOG_(INFO) << "FaultLoggerdSystemTest015: end.";
2251 }
2252 }
2253
2254 /**
2255 * @tc.name: FaultLoggerdSystemTest016
2256 * @tc.desc: test CPP crasher application: SIGTRAP
2257 * @tc.type: FUNC
2258 */
2259 HWTEST_F (FaultLoggerdSystemTest, FaultLoggerdSystemTest016, TestSize.Level2)
2260 {
2261 GTEST_LOG_(INFO) << "FaultLoggerdSystemTest016: start.";
2262 std::string cmd = "SIGTRAP";
2263 int cppTest = 1;
2264 string filePathPid = FaultLoggerdSystemTest::GetfileNamePrefix(cmd, cppTest);
2265 if (filePathPid.size() < NUMBER_TEN) {
2266 EXPECT_EQ(true, false) << "ProcessDfxRequestTest016 Failed";
2267 } else {
2268 GTEST_LOG_(INFO) << "current filePath and pid = \n" << filePathPid;
2269 char filePath[ARRAY_SIZE_HUNDRED] = { 0, };
2270 char pid[ARRAY_SIZE_HUNDRED] = { 0, };
2271 int res = sscanf_s(filePathPid.c_str(), "%s %s", filePath, sizeof(filePath) - 1, pid, sizeof(pid) - 1);
2272 if (res <= 0) {
2273 GTEST_LOG_(INFO) << "sscanf_s failed.";
2274 }
2275 GTEST_LOG_(INFO) << "current filepath: \n" << filePath;
2276 GTEST_LOG_(INFO) << "current pid: \n" << pid;
2277 std::string filePathStr = filePath;
2278 std::string pidStr = pid;
2279 int ret = FaultLoggerdSystemTest::CheckCountNum(filePathStr, pidStr, cmd);
2280
2281 GTEST_LOG_(INFO) << "current ret value: \n" << ret;
2282 EXPECT_EQ(ret, 0) << "ProcessDfxRequestTest016 Failed";
2283 GTEST_LOG_(INFO) << "FaultLoggerdSystemTest016: end.";
2284 }
2285 }
2286
2287 /**
2288 * @tc.name: FaultLoggerdSystemTest017
2289 * @tc.desc: test CPP crasher application: SIGABRT
2290 * @tc.type: FUNC
2291 */
2292 HWTEST_F (FaultLoggerdSystemTest, FaultLoggerdSystemTest017, TestSize.Level2)
2293 {
2294 GTEST_LOG_(INFO) << "FaultLoggerdSystemTest017: start.";
2295 std::string cmd = "SIGABRT";
2296 int cppTest = 1;
2297 std::string filePathPid = FaultLoggerdSystemTest::GetfileNamePrefix(cmd, cppTest);
2298 if (filePathPid.size() < NUMBER_TEN) {
2299 EXPECT_EQ(true, false) << "ProcessDfxRequestTest017 Failed";
2300 } else {
2301 GTEST_LOG_(INFO) << "current filePath and pid = \n" << filePathPid;
2302 char filePath[ARRAY_SIZE_HUNDRED] = { 0, };
2303 char pid[ARRAY_SIZE_HUNDRED] = { 0, };
2304 int res = sscanf_s(filePathPid.c_str(), "%s %s", filePath, sizeof(filePath) - 1, pid, sizeof(pid) - 1);
2305 if (res <= 0) {
2306 GTEST_LOG_(INFO) << "sscanf_s failed.";
2307 }
2308 GTEST_LOG_(INFO) << "current filepath: \n" << filePath;
2309 GTEST_LOG_(INFO) << "current pid: \n" << pid;
2310 std::string filePathStr = filePath;
2311 std::string pidStr = pid;
2312 int ret = FaultLoggerdSystemTest::CheckCountNumAbort(filePathStr, pidStr);
2313
2314 GTEST_LOG_(INFO) << "current ret value: \n" << ret;
2315 EXPECT_EQ(ret, 0) << "ProcessDfxRequestTest017 Failed";
2316 GTEST_LOG_(INFO) << "FaultLoggerdSystemTest017: end.";
2317 }
2318 }
2319
2320 /**
2321 * @tc.name: FaultLoggerdSystemTest018
2322 * @tc.desc: test CPP crasher application: SIGBUS
2323 * @tc.type: FUNC
2324 */
2325 HWTEST_F (FaultLoggerdSystemTest, FaultLoggerdSystemTest018, TestSize.Level2)
2326 {
2327 GTEST_LOG_(INFO) << "FaultLoggerdSystemTest018: start.";
2328 std::string cmd = "SIGBUS";
2329 int cppTest = 1;
2330 string filePathPid = FaultLoggerdSystemTest::GetfileNamePrefix(cmd, cppTest);
2331 if (filePathPid.size() < NUMBER_TEN) {
2332 EXPECT_EQ(true, false) << "ProcessDfxRequestTest018 Failed";
2333 } else {
2334 GTEST_LOG_(INFO) << "current filePath and pid = \n" << filePathPid;
2335 char filePath[ARRAY_SIZE_HUNDRED] = { 0, };
2336 char pid[ARRAY_SIZE_HUNDRED] = { 0, };
2337 int res = sscanf_s(filePathPid.c_str(), "%s %s", filePath, sizeof(filePath) - 1, pid, sizeof(pid) - 1);
2338 if (res <= 0) {
2339 GTEST_LOG_(INFO) << "sscanf_s failed.";
2340 }
2341 GTEST_LOG_(INFO) << "current filepath: \n" << filePath;
2342 GTEST_LOG_(INFO) << "current pid: \n" << pid;
2343 std::string filePathStr = filePath;
2344 std::string pidStr = pid;
2345 int ret = FaultLoggerdSystemTest::CheckCountNum(filePathStr, pidStr, cmd);
2346
2347 GTEST_LOG_(INFO) << "current ret value: \n" << ret;
2348 EXPECT_EQ(ret, 0) << "ProcessDfxRequestTest018 Failed";
2349 GTEST_LOG_(INFO) << "FaultLoggerdSystemTest018: end.";
2350 }
2351 }
2352
2353 /**
2354 * @tc.name: FaultLoggerdSystemTest019
2355 * @tc.desc: test CPP crasher application: STACKTRACE
2356 * @tc.type: FUNC
2357 */
2358 HWTEST_F (FaultLoggerdSystemTest, FaultLoggerdSystemTest019, TestSize.Level2)
2359 {
2360 GTEST_LOG_(INFO) << "FaultLoggerdSystemTest019: start.";
2361 std::string cmd = "STACKTRACE";
2362 GTEST_LOG_(INFO) << "FaultLoggerdSystemTest019: end.";
2363 }
2364
2365 /**
2366 * @tc.name: FaultLoggerdSystemTest020
2367 * @tc.desc: test CPP crasher application: triSIGTRAP
2368 * @tc.type: FUNC
2369 */
2370 HWTEST_F (FaultLoggerdSystemTest, FaultLoggerdSystemTest020, TestSize.Level2)
2371 {
2372 GTEST_LOG_(INFO) << "FaultLoggerdSystemTest020: start.";
2373 std::string cmd = "triSIGTRAP";
2374 int cppTest = 1;
2375 string filePathPid = FaultLoggerdSystemTest::GetfileNamePrefix(cmd, cppTest);
2376 if (filePathPid.size() < NUMBER_TEN) {
2377 EXPECT_EQ(true, false) << "ProcessDfxRequestTest020 Failed";
2378 } else {
2379 GTEST_LOG_(INFO) << "current filePath and pid = \n" << filePathPid;
2380 char filePath[ARRAY_SIZE_HUNDRED] = { 0, };
2381 char pid[ARRAY_SIZE_HUNDRED] = { 0, };
2382 int res = sscanf_s(filePathPid.c_str(), "%s %s", filePath, sizeof(filePath) - 1, pid, sizeof(pid) - 1);
2383 if (res <= 0) {
2384 GTEST_LOG_(INFO) << "sscanf_s failed.";
2385 }
2386 GTEST_LOG_(INFO) << "current filepath: \n" << filePath;
2387 GTEST_LOG_(INFO) << "current pid: \n" << pid;
2388 std::string filePathStr = filePath;
2389 std::string pidStr = pid;
2390 int ret = FaultLoggerdSystemTest::CheckCountNum(filePathStr, pidStr, cmd);
2391
2392 GTEST_LOG_(INFO) << "current ret value: \n" << ret;
2393 EXPECT_EQ(ret, 0) << "ProcessDfxRequestTest020 Failed";
2394 GTEST_LOG_(INFO) << "FaultLoggerdSystemTest020: end.";
2395 }
2396 }
2397
2398 /**
2399 * @tc.name: FaultLoggerdSystemTest021
2400 * @tc.desc: test CPP crasher application: triSIGSEGV
2401 * @tc.type: FUNC
2402 */
2403 HWTEST_F (FaultLoggerdSystemTest, FaultLoggerdSystemTest021, TestSize.Level2)
2404 {
2405 GTEST_LOG_(INFO) << "FaultLoggerdSystemTest021: start.";
2406 std::string cmd = "triSIGSEGV";
2407 int cppTest = 1;
2408 std::string filePathPid = FaultLoggerdSystemTest::GetfileNamePrefix(cmd, cppTest);
2409 if (filePathPid.size() < NUMBER_TEN) {
2410 EXPECT_EQ(true, false) << "ProcessDfxRequestTest021 Failed";
2411 } else {
2412 GTEST_LOG_(INFO) << "current filePath and pid = \n" << filePathPid;
2413 char filePath[ARRAY_SIZE_HUNDRED] = { 0, };
2414 char pid[ARRAY_SIZE_HUNDRED] = { 0, };
2415 int res = sscanf_s(filePathPid.c_str(), "%s %s", filePath, sizeof(filePath) - 1, pid, sizeof(pid) - 1);
2416 if (res <= 0) {
2417 GTEST_LOG_(INFO) << "sscanf_s failed.";
2418 }
2419 GTEST_LOG_(INFO) << "current filepath: \n" << filePath;
2420 GTEST_LOG_(INFO) << "current pid: \n" << pid;
2421 std::string filePathStr = filePath;
2422 std::string pidStr = pid;
2423 int ret = FaultLoggerdSystemTest::CheckCountNum(filePathStr, pidStr, cmd);
2424
2425 GTEST_LOG_(INFO) << "current ret value: \n" << ret;
2426 EXPECT_EQ(ret, 0) << "ProcessDfxRequestTest021 Failed";
2427 GTEST_LOG_(INFO) << "FaultLoggerdSystemTest021: end.";
2428 }
2429 }
2430
2431 /**
2432 * @tc.name: FaultLoggerdSystemTest022
2433 * @tc.desc: test CPPcrasher application: MaxStack
2434 * @tc.type: FUNC
2435 */
2436 HWTEST_F (FaultLoggerdSystemTest, FaultLoggerdSystemTest022, TestSize.Level2)
2437 {
2438 GTEST_LOG_(INFO) << "FaultLoggerdSystemTest022: start.";
2439 std::string cmd = "MaxStack";
2440 int cppTest = 1;
2441 string filePathPid = FaultLoggerdSystemTest::GetfileNamePrefix(cmd, cppTest);
2442 if (filePathPid.size() < NUMBER_TEN) {
2443 EXPECT_EQ(true, false) << "ProcessDfxRequestTest022 Failed";
2444 } else {
2445 GTEST_LOG_(INFO) << "current filePath and pid = \n" << filePathPid;
2446 char filePath[ARRAY_SIZE_HUNDRED] = { 0, };
2447 char pid[ARRAY_SIZE_HUNDRED] = { 0, };
2448 int res = sscanf_s(filePathPid.c_str(), "%s %s", filePath, sizeof(filePath) - 1, pid, sizeof(pid) - 1);
2449 if (res <= 0) {
2450 GTEST_LOG_(INFO) << "sscanf_s failed.";
2451 }
2452 GTEST_LOG_(INFO) << "current filepath: \n" << filePath;
2453 GTEST_LOG_(INFO) << "current pid: \n" << pid;
2454 std::string filePathStr = filePath;
2455 std::string pidStr = pid;
2456 int ret = FaultLoggerdSystemTest::CheckCountNum(filePathStr, pidStr, cmd);
2457
2458 GTEST_LOG_(INFO) << "current ret value: \n" << ret;
2459 EXPECT_EQ(ret, 0) << "ProcessDfxRequestTest022 Failed";
2460 GTEST_LOG_(INFO) << "FaultLoggerdSystemTest022: end.";
2461 }
2462 }
2463
2464 /**
2465 * @tc.name: FaultLoggerdSystemTest023
2466 * @tc.desc: test CPP crasher application: MaxMethod
2467 * @tc.type: FUNC
2468 */
2469 HWTEST_F (FaultLoggerdSystemTest, FaultLoggerdSystemTest023, TestSize.Level2)
2470 {
2471 GTEST_LOG_(INFO) << "FaultLoggerdSystemTest023: start.";
2472 std::string cmd = "MaxMethod";
2473 int cppTest = 1;
2474 string filePathPid = FaultLoggerdSystemTest::GetfileNamePrefix(cmd, cppTest);
2475 if (filePathPid.size() < NUMBER_TEN) {
2476 EXPECT_EQ(true, false) << "ProcessDfxRequestTest023 Failed";
2477 } else {
2478 GTEST_LOG_(INFO) << "current filePath and pid = \n" << filePathPid;
2479 char filePath[ARRAY_SIZE_HUNDRED] = { 0, };
2480 char pid[ARRAY_SIZE_HUNDRED] = { 0, };
2481 int res = sscanf_s(filePathPid.c_str(), "%s %s", filePath, sizeof(filePath) - 1, pid, sizeof(pid) - 1);
2482 if (res <= 0) {
2483 GTEST_LOG_(INFO) << "sscanf_s failed.";
2484 }
2485 GTEST_LOG_(INFO) << "current filepath: \n" << filePath;
2486 GTEST_LOG_(INFO) << "current pid: \n" << pid;
2487 std::string filePathStr = filePath;
2488 std::string pidStr = pid;
2489 int ret = FaultLoggerdSystemTest::CheckCountNum(filePathStr, pidStr, cmd);
2490 GTEST_LOG_(INFO) << "current ret value: \n" << ret;
2491 EXPECT_EQ(ret, 0) << "ProcessDfxRequestTest023 Failed";
2492 GTEST_LOG_(INFO) << "FaultLoggerdSystemTest023: end.";
2493 }
2494 }
2495
2496 /**
2497 * @tc.name: FaultLoggerdSystemTest025
2498 * @tc.desc: test DumpCatch API: app PID(app), TID(0)
2499 * @tc.type: FUNC
2500 */
2501 HWTEST_F (FaultLoggerdSystemTest, FaultLoggerdSystemTest025, TestSize.Level2)
2502 {
2503 GTEST_LOG_(INFO) << "FaultLoggerdSystemTest025: start.";
2504 FaultLoggerdSystemTest::StartCrasherLoop(3);
2505 DfxDumpCatcher dumplog;
2506 std::string msg = "";
2507 GTEST_LOG_(INFO) << "appPid: " << FaultLoggerdSystemTest::loopAppPid;
2508 bool ret = dumplog.DumpCatch(FaultLoggerdSystemTest::loopAppPid, 0, msg);
2509 GTEST_LOG_(INFO) << ret;
2510 GTEST_LOG_(INFO) << msg;
2511 string log[] = { "Tid:", "#00", "/data/crasher", "Name:SubTestThread", "usleep"};
2512 log[0] = log[0] + std::to_string(FaultLoggerdSystemTest::loopAppPid) + ", Name:crasher";
2513 GTEST_LOG_(INFO) << "dump log : \n" << msg;
2514 string::size_type idx;
2515 int j = 0;
2516 int count = 0;
2517 for (int x = 0; x < 5; x = x + 1) {
2518 idx = msg.find(log[j]);
2519 GTEST_LOG_(INFO) << log[j];
2520 if (idx != string::npos) {
2521 count++;
2522 }
2523 j++;
2524 }
2525 EXPECT_EQ(count, 5) << "FaultLoggerdSystemTest025 Failed";
2526 FaultLoggerdSystemTest::KillCrasherLoopForSomeCase(3);
2527 GTEST_LOG_(INFO) << "FaultLoggerdSystemTest025: end.";
2528 }
2529
2530 /**
2531 * @tc.name: FaultLoggerdSystemTest026
2532 * @tc.desc: test DumpCatch API: app PID(app), TID(PID)
2533 * @tc.type: FUNC
2534 */
2535 HWTEST_F (FaultLoggerdSystemTest, FaultLoggerdSystemTest026, TestSize.Level2)
2536 {
2537 GTEST_LOG_(INFO) << "FaultLoggerdSystemTest026: start.";
2538 FaultLoggerdSystemTest::StartCrasherLoop(3);
2539 DfxDumpCatcher dumplog;
2540 std::string msg = "";
2541 bool ret = dumplog.DumpCatch(FaultLoggerdSystemTest::loopAppPid, FaultLoggerdSystemTest::loopAppPid, msg);
2542 GTEST_LOG_(INFO) << ret;
2543 GTEST_LOG_(INFO) << msg;
2544 int count = 0;
2545 string log[] = {"Tid:", "Name:crasher", "#00", "/data/crasher"};
2546 log[0] = log[0] +std::to_string(FaultLoggerdSystemTest::loopAppPid);
2547 string::size_type idx;
2548 int j = 0;
2549 for (int x = 0; x < 4; x = x + 1) {
2550 idx = msg.find(log[j]);
2551 if (idx != string::npos) {
2552 count++;
2553 }
2554 j++;
2555 }
2556 GTEST_LOG_(INFO) << count;
2557 EXPECT_EQ(count, 4) << "FaultLoggerdSystemTest026 Failed";
2558 FaultLoggerdSystemTest::KillCrasherLoopForSomeCase(3);
2559 GTEST_LOG_(INFO) << "FaultLoggerdSystemTest026: end.";
2560 }
2561
2562 /**
2563 * @tc.name: FaultLoggerdSystemTest026_level0
2564 * @tc.desc: test DumpCatch API: app PID(app), TID(PID)
2565 * @tc.type: FUNC
2566 */
2567 HWTEST_F (FaultLoggerdSystemTest, FaultLoggerdSystemTest026_level0, TestSize.Level0)
2568 {
2569 GTEST_LOG_(INFO) << "FaultLoggerdSystemTest026_level0: start.";
2570 FaultLoggerdSystemTest::StartCrasherLoop(3);
2571 DfxDumpCatcher dumplog;
2572 std::string msg = "";
2573 bool ret = dumplog.DumpCatch(FaultLoggerdSystemTest::loopAppPid, FaultLoggerdSystemTest::loopAppPid, msg);
2574 GTEST_LOG_(INFO) << ret;
2575 GTEST_LOG_(INFO) << msg;
2576 int count = 0;
2577 string log[] = {"Tid:", "Name:crasher", "#00", "/data/crasher"};
2578 log[0] = log[0] +std::to_string(FaultLoggerdSystemTest::loopAppPid);
2579 string::size_type idx;
2580 int j = 0;
2581 for (int x = 0; x < 4; x = x + 1) {
2582 idx = msg.find(log[j]);
2583 if (idx != string::npos) {
2584 count++;
2585 }
2586 j++;
2587 }
2588 GTEST_LOG_(INFO) << count;
2589 EXPECT_EQ(count, 4) << "FaultLoggerdSystemTest026_level0 Failed";
2590 FaultLoggerdSystemTest::KillCrasherLoopForSomeCase(3);
2591 GTEST_LOG_(INFO) << "FaultLoggerdSystemTest026_level0: end.";
2592 }
2593
2594 /**
2595 * @tc.name: FaultLoggerdSystemTest027
2596 * @tc.desc: test DumpCatch API: app PID(app), TID(<>PID)
2597 * @tc.type: FUNC
2598 */
2599 HWTEST_F (FaultLoggerdSystemTest, FaultLoggerdSystemTest027, TestSize.Level2)
2600 {
2601 GTEST_LOG_(INFO) << "FaultLoggerdSystemTest027: start.";
2602 FaultLoggerdSystemTest::StartCrasherLoop(3);
2603 DfxDumpCatcher dumplog;
2604 std::string msg = "";
2605 int tid = std::stoi(appTid[0]);
2606 if (FaultLoggerdSystemTest::loopAppPid == std::stoi(FaultLoggerdSystemTest::appTid[0])) {
2607 tid = std::stoi(appTid[1]);
2608 }
2609 dumplog.DumpCatch(FaultLoggerdSystemTest::loopAppPid, tid, msg);
2610 int count = 0;
2611 GTEST_LOG_(INFO) << msg;
2612 string log[] = {"Tid:", "#00", "/data/crasher"};
2613 log[0] = log[0] + std::to_string(tid) + ", Name:SubTestThread";
2614 GTEST_LOG_(INFO) << log[0];
2615 string::size_type idx;
2616 int j = 0;
2617 for (int x = 0; x < 3; x = x + 1) {
2618 idx = msg.find(log[j]);
2619 if (idx != string::npos) {
2620 GTEST_LOG_(INFO) << log[j];
2621 count++;
2622 }
2623 j++;
2624 }
2625
2626 EXPECT_EQ(count, 3) << "FaultLoggerdSystemTest027 Failed";
2627 FaultLoggerdSystemTest::KillCrasherLoopForSomeCase(3);
2628 GTEST_LOG_(INFO) << "FaultLoggerdSystemTest027: end.";
2629 }
2630
2631 /**
2632 * @tc.name: FaultLoggerdSystemTest028
2633 * @tc.desc: test DumpCatch API: app PID(system), TID(0)
2634 * @tc.type: FUNC
2635 */
2636 HWTEST_F (FaultLoggerdSystemTest, FaultLoggerdSystemTest028, TestSize.Level2)
2637 {
2638 GTEST_LOG_(INFO) << "FaultLoggerdSystemTest028: start.";
2639 FaultLoggerdSystemTest::StartCrasherLoop(1);
2640 FaultLoggerdSystemTest::StartCrasherLoop(3);
2641 DfxDumpCatcher dumplog;
2642 std::string msg = "";
2643 bool ret = dumplog.DumpCatch(FaultLoggerdSystemTest::loopSysPid, 0, msg);
2644 GTEST_LOG_(INFO) << ret;
2645 GTEST_LOG_(INFO) << "dump log : \n" << msg;
2646 EXPECT_EQ(ret, true) << "FaultLoggerdSystemTest028 Failed";
2647 FaultLoggerdSystemTest::KillCrasherLoopForSomeCase(1);
2648 FaultLoggerdSystemTest::KillCrasherLoopForSomeCase(3);
2649 GTEST_LOG_(INFO) << "FaultLoggerdSystemTest028: end.";
2650 }
2651
2652 /**
2653 * @tc.name: FaultLoggerdSystemTest0104
2654 * @tc.desc: test DumpCatch API: app PID(root), TID(0)
2655 * @tc.type: FUNC
2656 */
2657 HWTEST_F (FaultLoggerdSystemTest, FaultLoggerdSystemTest0104, TestSize.Level2)
2658 {
2659 GTEST_LOG_(INFO) << "FaultLoggerdSystemTest0104: start.";
2660 FaultLoggerdSystemTest::StartCrasherLoop(2);
2661 FaultLoggerdSystemTest::StartCrasherLoop(3);
2662 int uidSetting = OTHER_UID;
2663 setuid(uidSetting);
2664 DfxDumpCatcher dumplog;
2665 std::string msg = "";
2666 bool ret = dumplog.DumpCatch(FaultLoggerdSystemTest::loopRootPid, 0, msg);
2667 GTEST_LOG_(INFO) << ret;
2668 GTEST_LOG_(INFO) << "dump log : \n" << msg;
2669 EXPECT_EQ(ret, true) << "FaultLoggerdSystemTest0104 Failed";
2670 FaultLoggerdSystemTest::KillCrasherLoopForSomeCase(2);
2671 FaultLoggerdSystemTest::KillCrasherLoopForSomeCase(3);
2672 GTEST_LOG_(INFO) << "FaultLoggerdSystemTest0104: end.";
2673 }
2674
2675 /**
2676 * @tc.name: FaultLoggerdSystemTest029
2677 * @tc.desc: test DumpCatch API: app PID(9999), TID(0)
2678 * @tc.type: FUNC
2679 */
2680 HWTEST_F (FaultLoggerdSystemTest, FaultLoggerdSystemTest029, TestSize.Level2)
2681 {
2682 GTEST_LOG_(INFO) << "FaultLoggerdSystemTest029: start.";
2683 FaultLoggerdSystemTest::StartCrasherLoop(3);
2684 DfxDumpCatcher dumplog;
2685 std::string msg = "";
2686 bool ret = dumplog.DumpCatch(9999, 0, msg);
2687 GTEST_LOG_(INFO) << ret;
2688 GTEST_LOG_(INFO) << "dump log : \n" << msg;
2689 EXPECT_EQ(ret, false) << "FaultLoggerdSystemTest029 Failed";
2690 FaultLoggerdSystemTest::KillCrasherLoopForSomeCase(3);
2691 GTEST_LOG_(INFO) << "FaultLoggerdSystemTest029: end.";
2692 }
2693
2694 /**
2695 * @tc.name: FaultLoggerdSystemTest030
2696 * @tc.desc: test DumpCatch API: app PID(app), TID(9999)
2697 * @tc.type: FUNC
2698 */
2699 HWTEST_F (FaultLoggerdSystemTest, FaultLoggerdSystemTest030, TestSize.Level2)
2700 {
2701 GTEST_LOG_(INFO) << "FaultLoggerdSystemTest030: start.";
2702 FaultLoggerdSystemTest::StartCrasherLoop(3);
2703 DfxDumpCatcher dumplog;
2704 std::string msg = "";
2705 bool ret = dumplog.DumpCatch(FaultLoggerdSystemTest::loopAppPid, 9999, msg);
2706 GTEST_LOG_(INFO) << ret;
2707 GTEST_LOG_(INFO) << "dump log : \n" << msg;
2708 EXPECT_EQ(ret, false) << "FaultLoggerdSystemTest030 Failed";
2709 FaultLoggerdSystemTest::KillCrasherLoopForSomeCase(3);
2710 GTEST_LOG_(INFO) << "FaultLoggerdSystemTest030: end.";
2711 }
2712
2713 /**
2714 * @tc.name: FaultLoggerdSystemTest031
2715 * @tc.desc: test DumpCatch API: app PID(app), TID(system)
2716 * @tc.type: FUNC
2717 */
2718 HWTEST_F (FaultLoggerdSystemTest, FaultLoggerdSystemTest031, TestSize.Level2)
2719 {
2720 GTEST_LOG_(INFO) << "FaultLoggerdSystemTest031 start.";
2721 FaultLoggerdSystemTest::StartCrasherLoop(1);
2722 FaultLoggerdSystemTest::StartCrasherLoop(3);
2723 DfxDumpCatcher dumplog;
2724 std::string msg = "";
2725 bool ret = dumplog.DumpCatch(FaultLoggerdSystemTest::loopAppPid, FaultLoggerdSystemTest::loopSysPid, msg);
2726 GTEST_LOG_(INFO) << ret;
2727 GTEST_LOG_(INFO) << "dump log : \n" << msg;
2728 EXPECT_EQ(ret, false) << "FaultLoggerdSystemTest031 Failed";
2729 FaultLoggerdSystemTest::KillCrasherLoopForSomeCase(1);
2730 FaultLoggerdSystemTest::KillCrasherLoopForSomeCase(3);
2731 GTEST_LOG_(INFO) << "FaultLoggerdSystemTest031: end.";
2732 }
2733
2734 /**
2735 * @tc.name: FaultLoggerdSystemTest032
2736 * @tc.desc: test DumpCatch API: app PID(Null), TID(app)
2737 * @tc.type: FUNC
2738 */
2739 HWTEST_F (FaultLoggerdSystemTest, FaultLoggerdSystemTest032, TestSize.Level2)
2740 {
2741 GTEST_LOG_(INFO) << "FaultLoggerdSystemTest032 start.";
2742 FaultLoggerdSystemTest::StartCrasherLoop(3);
2743 int uidSetting = OTHER_UID;
2744 setuid(uidSetting);
2745 DfxDumpCatcher dumplog;
2746 std::string msg = "";
2747 bool ret = dumplog.DumpCatch(0, FaultLoggerdSystemTest::loopAppPid, msg);
2748 GTEST_LOG_(INFO) << ret;
2749 GTEST_LOG_(INFO) << "dump log : \n" << msg;
2750 EXPECT_EQ(ret, false) << "FaultLoggerdSystemTest032 Failed";
2751 FaultLoggerdSystemTest::KillCrasherLoopForSomeCase(3);
2752 GTEST_LOG_(INFO) << "FaultLoggerdSystemTest032: end.";
2753 }
2754
2755 /**
2756 * @tc.name: FaultLoggerdSystemTest034
2757 * @tc.desc: test DumpCatch API: PID(-11), TID(0)
2758 * @tc.type: FUNC
2759 */
2760 HWTEST_F (FaultLoggerdSystemTest, FaultLoggerdSystemTest034, TestSize.Level2)
2761 {
2762 GTEST_LOG_(INFO) << "FaultLoggerdSystemTest034 start.";
2763 FaultLoggerdSystemTest::StartCrasherLoop(3);
2764 DfxDumpCatcher dumplog;
2765 std::string msg = "";
2766 bool ret = dumplog.DumpCatch(-11, 0, msg);
2767 GTEST_LOG_(INFO) << ret;
2768 GTEST_LOG_(INFO) << "dump log : \n" << msg;
2769 EXPECT_EQ(ret, false) << "FaultLoggerdSystemTest034 Failed";
2770 FaultLoggerdSystemTest::KillCrasherLoopForSomeCase(3);
2771 GTEST_LOG_(INFO) << "FaultLoggerdSystemTest034: end.";
2772 }
2773
2774 /**
2775 * @tc.name: FaultLoggerdSystemTest035
2776 * @tc.desc: test DumpCatch API: PID(root), TID(-11)
2777 * @tc.type: FUNC
2778 */
2779 HWTEST_F (FaultLoggerdSystemTest, FaultLoggerdSystemTest035, TestSize.Level2)
2780 {
2781 GTEST_LOG_(INFO) << "FaultLoggerdSystemTest035 start.";
2782 FaultLoggerdSystemTest::StartCrasherLoop(3);
2783 DfxDumpCatcher dumplog;
2784 std::string msg = "";
2785 bool ret = dumplog.DumpCatch(FaultLoggerdSystemTest::loopRootPid, -11, msg);
2786 GTEST_LOG_(INFO) << ret;
2787 GTEST_LOG_(INFO) << "dump log : \n" << msg;
2788 EXPECT_EQ(ret, false) << "FaultLoggerdSystemTest035 Failed";
2789 FaultLoggerdSystemTest::KillCrasherLoopForSomeCase(3);
2790 GTEST_LOG_(INFO) << "FaultLoggerdSystemTest035: end.";
2791 }
2792
2793 /**
2794 * @tc.name: FaultLoggerdSystemTest036
2795 * @tc.desc: test DumpCatch API: system PID(system), TID(0)
2796 * @tc.type: FUNC
2797 */
2798 HWTEST_F (FaultLoggerdSystemTest, FaultLoggerdSystemTest036, TestSize.Level2)
2799 {
2800 GTEST_LOG_(INFO) << "FaultLoggerdSystemTest036: start.";
2801 FaultLoggerdSystemTest::StartCrasherLoop(1);
2802 int uidSetting = BMS_UID;
2803 setuid(uidSetting);
2804 DfxDumpCatcher dumplog;
2805 std::string msg = "";
2806 bool ret = dumplog.DumpCatch(FaultLoggerdSystemTest::loopSysPid, 0, msg);
2807 GTEST_LOG_(INFO) << "loopSysPid : \n" << FaultLoggerdSystemTest::loopSysPid;
2808 string log[] = { "Tid:", "#00", "/data/crasher", "Name:SubTestThread", "usleep"};
2809 log[0] = log[0] +std::to_string(FaultLoggerdSystemTest::loopSysPid) + ", Name:crasher";
2810 GTEST_LOG_(INFO) << "ret : \n" << ret;
2811 GTEST_LOG_(INFO) << "dump log : \n" << msg;
2812 string::size_type idx;
2813 int j = 0;
2814 int count = 0;
2815 for (int x = 0; x < 5; x = x + 1) {
2816 idx = msg.find(log[j]);
2817 GTEST_LOG_(INFO) << log[j];
2818 if (idx != string::npos) {
2819 count++;
2820 }
2821 j++;
2822 }
2823 int otheruid = OTHER_UID;
2824 setuid(otheruid);
2825 EXPECT_EQ(count, 5) << "FaultLoggerdSystemTest036 Failed";
2826 FaultLoggerdSystemTest::KillCrasherLoopForSomeCase(1);
2827 GTEST_LOG_(INFO) << "FaultLoggerdSystemTest036: end.";
2828 }
2829
2830 /**
2831 * @tc.name: FaultLoggerdSystemTest0100
2832 * @tc.desc: test DumpCatch API: root PID(root), TID(0)
2833 * @tc.type: FUNC
2834 */
2835 HWTEST_F (FaultLoggerdSystemTest, FaultLoggerdSystemTest0100, TestSize.Level2)
2836 {
2837 GTEST_LOG_(INFO) << "FaultLoggerdSystemTest0100: start.";
2838 FaultLoggerdSystemTest::StartCrasherLoop(2);
2839 int uidSetting = 0;
2840 setuid(uidSetting);
2841 DfxDumpCatcher dumplog;
2842 std::string msg = "";
2843 bool ret = dumplog.DumpCatch(FaultLoggerdSystemTest::loopRootPid, 0, msg);
2844 GTEST_LOG_(INFO) << "loopRootPid : \n" << FaultLoggerdSystemTest::loopRootPid;
2845 string log[] = { "Tid:", "#00", "/data/crasher", "Name:SubTestThread", "usleep"};
2846 log[0] = log[0] +std::to_string(FaultLoggerdSystemTest::loopRootPid) + ", Name:crasher";
2847 GTEST_LOG_(INFO) << "ret : \n" << ret;
2848 GTEST_LOG_(INFO) << "dump log : \n" << msg;
2849 string::size_type idx;
2850 int j = 0;
2851 int count = 0;
2852 for (int x = 0; x < 5; x = x + 1) {
2853 idx = msg.find(log[j]);
2854 GTEST_LOG_(INFO) << log[j];
2855 if (idx != string::npos) {
2856 count++;
2857 }
2858 j++;
2859 }
2860 int otheruid = OTHER_UID;
2861 setuid(otheruid);
2862 EXPECT_EQ(count, 5) << "FaultLoggerdSystemTest0100 Failed";
2863 FaultLoggerdSystemTest::KillCrasherLoopForSomeCase(2);
2864 GTEST_LOG_(INFO) << "FaultLoggerdSystemTest0100: end.";
2865 }
2866
2867 /**
2868 * @tc.name: FaultLoggerdSystemTest037
2869 * @tc.desc: test DumpCatch API: system PID(app), TID(0)
2870 * @tc.type: FUNC
2871 */
2872 HWTEST_F (FaultLoggerdSystemTest, FaultLoggerdSystemTest037, TestSize.Level2)
2873 {
2874 GTEST_LOG_(INFO) << "FaultLoggerdSystemTest037: start.";
2875 FaultLoggerdSystemTest::StartCrasherLoop(1);
2876 FaultLoggerdSystemTest::StartCrasherLoop(3);
2877 int uidSetting = BMS_UID;
2878 setuid(uidSetting);
2879 DfxDumpCatcher dumplog;
2880 std::string msg = "";
2881 bool ret = dumplog.DumpCatch(FaultLoggerdSystemTest::loopAppPid, 0, msg);
2882 GTEST_LOG_(INFO) << "ret : \n" << ret;
2883 GTEST_LOG_(INFO) << "dump log : \n" << msg;
2884 GTEST_LOG_(INFO) << "FaultLoggerdSystemTest::loopAppPid : \n" << FaultLoggerdSystemTest::loopAppPid;
2885 string log[] = { "Tid:", "#00", "/data/crasher", "Name:SubTestThread", "usleep"};
2886 log[0] = log[0] +std::to_string(FaultLoggerdSystemTest::loopAppPid) + ", Name:crasher";
2887 GTEST_LOG_(INFO) << "ret : \n" << ret;
2888 GTEST_LOG_(INFO) << "dump log : \n" << msg;
2889 string::size_type idx;
2890 int j = 0;
2891 int count = 0;
2892 for (int x = 0; x < 5; x = x + 1) {
2893 idx = msg.find(log[j]);
2894 GTEST_LOG_(INFO) << log[j];
2895 if (idx != string::npos) {
2896 count++;
2897 }
2898 j++;
2899 }
2900 int otheruid = OTHER_UID;
2901 setuid(otheruid);
2902 EXPECT_EQ(count, 5) << "FaultLoggerdSystemTest037 Failed";
2903 FaultLoggerdSystemTest::KillCrasherLoopForSomeCase(1);
2904 FaultLoggerdSystemTest::KillCrasherLoopForSomeCase(3);
2905 GTEST_LOG_(INFO) << "FaultLoggerdSystemTest037: end.";
2906 }
2907
2908 /**
2909 * @tc.name: FaultLoggerdSystemTest0101
2910 * @tc.desc: test DumpCatch API: system PID(root), TID(0)
2911 * @tc.type: FUNC
2912 */
2913 HWTEST_F (FaultLoggerdSystemTest, FaultLoggerdSystemTest0101, TestSize.Level2)
2914 {
2915 GTEST_LOG_(INFO) << "FaultLoggerdSystemTest0101: start.";
2916 FaultLoggerdSystemTest::StartCrasherLoop(1);
2917 FaultLoggerdSystemTest::StartCrasherLoop(2);
2918 int uidSetting = BMS_UID;
2919 setuid(uidSetting);
2920 DfxDumpCatcher dumplog;
2921 std::string msg = "";
2922 bool ret = dumplog.DumpCatch(FaultLoggerdSystemTest::loopRootPid, 0, msg);
2923 GTEST_LOG_(INFO) << "ret : \n" << ret;
2924 GTEST_LOG_(INFO) << "dump log : \n" << msg;
2925 GTEST_LOG_(INFO) << "FaultLoggerdSystemTest::loopRootPid : \n" << FaultLoggerdSystemTest::loopRootPid;
2926 string log[] = { "Tid:", "#00", "/data/crasher", "Name:SubTestThread", "usleep"};
2927 log[0] = log[0] +std::to_string(FaultLoggerdSystemTest::loopRootPid) + ", Name:crasher";
2928 GTEST_LOG_(INFO) << "ret : \n" << ret;
2929 GTEST_LOG_(INFO) << "dump log : \n" << msg;
2930 string::size_type idx;
2931 int j = 0;
2932 int count = 0;
2933 for (int x = 0; x < 5; x = x + 1) {
2934 idx = msg.find(log[j]);
2935 GTEST_LOG_(INFO) << log[j];
2936 if (idx != string::npos) {
2937 count++;
2938 }
2939 j++;
2940 }
2941 int otheruid = OTHER_UID;
2942 setuid(otheruid);
2943 EXPECT_EQ(count, 5) << "FaultLoggerdSystemTest0101 Failed";
2944 FaultLoggerdSystemTest::KillCrasherLoopForSomeCase(1);
2945 FaultLoggerdSystemTest::KillCrasherLoopForSomeCase(2);
2946 GTEST_LOG_(INFO) << "FaultLoggerdSystemTest0101: end.";
2947 }
2948
2949 /**
2950 * @tc.name: FaultLoggerdSystemTest0102
2951 * @tc.desc: test DumpCatch API: root PID(system), TID(0)
2952 * @tc.type: FUNC
2953 */
2954 HWTEST_F (FaultLoggerdSystemTest, FaultLoggerdSystemTest0102, TestSize.Level2)
2955 {
2956 GTEST_LOG_(INFO) << "FaultLoggerdSystemTest0102: start.";
2957 FaultLoggerdSystemTest::StartCrasherLoop(1);
2958 FaultLoggerdSystemTest::StartCrasherLoop(2);
2959 int uidSetting = 0;
2960 setuid(uidSetting);
2961 DfxDumpCatcher dumplog;
2962 std::string msg = "";
2963 bool ret = dumplog.DumpCatch(FaultLoggerdSystemTest::loopSysPid, 0, msg);
2964 GTEST_LOG_(INFO) << "ret : \n" << ret;
2965 GTEST_LOG_(INFO) << "dump log : \n" << msg;
2966 GTEST_LOG_(INFO) << "FaultLoggerdSystemTest::loopSysPid : \n" << FaultLoggerdSystemTest::loopSysPid;
2967 string log[] = { "Tid:", "#00", "/data/crasher", "Name:SubTestThread", "usleep"};
2968 log[0] = log[0] +std::to_string(FaultLoggerdSystemTest::loopSysPid) + ", Name:crasher";
2969 GTEST_LOG_(INFO) << "ret : \n" << ret;
2970 GTEST_LOG_(INFO) << "dump log : \n" << msg;
2971 string::size_type idx;
2972 int j = 0;
2973 int count = 0;
2974 for (int x = 0; x < 5; x = x + 1) {
2975 idx = msg.find(log[j]);
2976 GTEST_LOG_(INFO) << log[j];
2977 if (idx != string::npos) {
2978 count++;
2979 }
2980 j++;
2981 }
2982 int otheruid = OTHER_UID;
2983 setuid(otheruid);
2984 EXPECT_EQ(count, 5) << "FaultLoggerdSystemTest0102 Failed";
2985 FaultLoggerdSystemTest::KillCrasherLoopForSomeCase(1);
2986 FaultLoggerdSystemTest::KillCrasherLoopForSomeCase(2);
2987 GTEST_LOG_(INFO) << "FaultLoggerdSystemTest0102: end.";
2988 }
2989
2990 /**
2991 * @tc.name: FaultLoggerdSystemTest0103
2992 * @tc.desc: test DumpCatch API: root PID(app), TID(0)
2993 * @tc.type: FUNC
2994 */
2995 HWTEST_F (FaultLoggerdSystemTest, FaultLoggerdSystemTest0103, TestSize.Level2)
2996 {
2997 GTEST_LOG_(INFO) << "FaultLoggerdSystemTest0103: start.";
2998 FaultLoggerdSystemTest::StartCrasherLoop(3);
2999 FaultLoggerdSystemTest::StartCrasherLoop(2);
3000 int uidSetting = 0;
3001 setuid(uidSetting);
3002 DfxDumpCatcher dumplog;
3003 std::string msg = "";
3004 bool ret = dumplog.DumpCatch(FaultLoggerdSystemTest::loopAppPid, 0, msg);
3005 GTEST_LOG_(INFO) << "ret : \n" << ret;
3006 GTEST_LOG_(INFO) << "dump log : \n" << msg;
3007 GTEST_LOG_(INFO) << "FaultLoggerdSystemTest::loopAppPid : \n" << FaultLoggerdSystemTest::loopAppPid;
3008 string log[] = { "Tid:", "#00", "/data/crasher", "Name:SubTestThread", "usleep"};
3009 log[0] = log[0] +std::to_string(FaultLoggerdSystemTest::loopAppPid) + ", Name:crasher";
3010 GTEST_LOG_(INFO) << "ret : \n" << ret;
3011 GTEST_LOG_(INFO) << "dump log : \n" << msg;
3012 string::size_type idx;
3013 int j = 0;
3014 int count = 0;
3015 for (int x = 0; x < 5; x = x + 1) {
3016 idx = msg.find(log[j]);
3017 GTEST_LOG_(INFO) << log[j];
3018 if (idx != string::npos) {
3019 count++;
3020 }
3021 j++;
3022 }
3023 int otheruid = OTHER_UID;
3024 setuid(otheruid);
3025 EXPECT_EQ(count, 5) << "FaultLoggerdSystemTest0103 Failed";
3026 FaultLoggerdSystemTest::KillCrasherLoopForSomeCase(3);
3027 FaultLoggerdSystemTest::KillCrasherLoopForSomeCase(2);
3028 GTEST_LOG_(INFO) << "FaultLoggerdSystemTest0103: end.";
3029 }
3030
3031 /**
3032 * @tc.name: FaultLoggerdSystemTest038
3033 * @tc.desc: test DumpCatch API: app PID(app), TID(root)
3034 * @tc.type: FUNC
3035 */
3036 HWTEST_F (FaultLoggerdSystemTest, FaultLoggerdSystemTest038, TestSize.Level2)
3037 {
3038 GTEST_LOG_(INFO) << "FaultLoggerdSystemTest038 start.";
3039 FaultLoggerdSystemTest::StartCrasherLoop(3);
3040 DfxDumpCatcher dumplog;
3041 std::string msg = "";
3042 bool ret = dumplog.DumpCatch(FaultLoggerdSystemTest::loopAppPid, FaultLoggerdSystemTest::loopRootPid, msg);
3043 GTEST_LOG_(INFO) << ret;
3044 GTEST_LOG_(INFO) << "dump log : \n" << msg;
3045 EXPECT_EQ(ret, false) << "FaultLoggerdSystemTest038 Failed";
3046 FaultLoggerdSystemTest::KillCrasherLoopForSomeCase(3);
3047 GTEST_LOG_(INFO) << "FaultLoggerdSystemTest038: end.";
3048 }
3049
3050 /**
3051 * @tc.name: FaultLoggerdSystemTest039
3052 * @tc.desc: test DumpCatch API: PID(root), TID(app)
3053 * @tc.type: FUNC
3054 */
3055 HWTEST_F (FaultLoggerdSystemTest, FaultLoggerdSystemTest039, TestSize.Level2)
3056 {
3057 GTEST_LOG_(INFO) << "FaultLoggerdSystemTest039 start.";
3058 FaultLoggerdSystemTest::StartCrasherLoop(3);
3059 DfxDumpCatcher dumplog;
3060 std::string msg = "";
3061 bool ret = dumplog.DumpCatch(FaultLoggerdSystemTest::loopRootPid, FaultLoggerdSystemTest::loopAppPid, msg);
3062 GTEST_LOG_(INFO) << ret;
3063 GTEST_LOG_(INFO) << "dump log : \n" << msg;
3064 EXPECT_EQ(ret, false) << "FaultLoggerdSystemTest039 Failed";
3065 FaultLoggerdSystemTest::KillCrasherLoopForSomeCase(3);
3066 GTEST_LOG_(INFO) << "FaultLoggerdSystemTest039: end.";
3067 }
3068
3069
3070 /**
3071 * @tc.name: FaultLoggerdSystemTest040
3072 * @tc.desc: test dumpcatcher command: dumpcatcher -p apppid
3073 * @tc.type: FUNC
3074 */
3075 HWTEST_F (FaultLoggerdSystemTest, FaultLoggerdSystemTest040, TestSize.Level2)
3076 {
3077 GTEST_LOG_(INFO) << "FaultLoggerdSystemTest040: start uid:" << getuid();
3078 FaultLoggerdSystemTest::StartCrasherLoop(3);
3079 std::string procCMD = "dumpcatcher -p " + std::to_string(FaultLoggerdSystemTest::loopAppPid);
3080 string procDumpLog = FaultLoggerdSystemTest::ProcessDumpCommands(procCMD);
3081 GTEST_LOG_(INFO) << "procDumpLog: " << procDumpLog;
3082 int count = 0;
3083 string log[] = {"", "Name:crasher", "Name:SubTestThread", "#00", "/data/crasher"};
3084 log[0] = log[0] + std::to_string(FaultLoggerdSystemTest::loopAppPid);
3085 string::size_type idx;
3086 for (int i = 0; i < 5; i++) {
3087 idx = procDumpLog.find(log[i]);
3088 if (idx != string::npos) {
3089 GTEST_LOG_(INFO) << log[i];
3090 count++;
3091 }
3092 }
3093 EXPECT_EQ(count, 5) << "FaultLoggerdSystemTest040 Failed";
3094 FaultLoggerdSystemTest::KillCrasherLoopForSomeCase(3);
3095 GTEST_LOG_(INFO) << "FaultLoggerdSystemTest040: end.";
3096 }
3097
3098 /**
3099 * @tc.name: FaultLoggerdSystemTest040_level0
3100 * @tc.desc: test dumpcatcher command: dumpcatcher -p apppid
3101 * @tc.type: FUNC
3102 */
3103 HWTEST_F (FaultLoggerdSystemTest, FaultLoggerdSystemTest040_level0, TestSize.Level0)
3104 {
3105 GTEST_LOG_(INFO) << "FaultLoggerdSystemTest040_level0: start uid:" << getuid();
3106 FaultLoggerdSystemTest::StartCrasherLoop(3);
3107 std::string procCMD = "dumpcatcher -p " + std::to_string(FaultLoggerdSystemTest::loopAppPid);
3108 string procDumpLog = FaultLoggerdSystemTest::ProcessDumpCommands(procCMD);
3109 GTEST_LOG_(INFO) << "procDumpLog: " << procDumpLog;
3110 int count = 0;
3111 string log[] = {"", "Name:crasher", "Name:SubTestThread", "#00", "/data/crasher"};
3112 log[0] = log[0] + std::to_string(FaultLoggerdSystemTest::loopAppPid);
3113 string::size_type idx;
3114 for (int i = 0; i < 5; i++) {
3115 idx = procDumpLog.find(log[i]);
3116 if (idx != string::npos) {
3117 GTEST_LOG_(INFO) << log[i];
3118 count++;
3119 }
3120 }
3121 EXPECT_EQ(count, 5) << "FaultLoggerdSystemTest040_level0 Failed";
3122 FaultLoggerdSystemTest::KillCrasherLoopForSomeCase(3);
3123 GTEST_LOG_(INFO) << "FaultLoggerdSystemTest040_level0: end.";
3124 }
3125
3126 /**
3127 * @tc.name: FaultLoggerdSystemTest041
3128 * @tc.desc: test dumpcatcher command: dumpcatcher -p apppid -t apppid
3129 * @tc.type: FUNC
3130 */
3131 HWTEST_F (FaultLoggerdSystemTest, FaultLoggerdSystemTest041, TestSize.Level2)
3132 {
3133 GTEST_LOG_(INFO) << "FaultLoggerdSystemTest041: start uid:" << getuid();
3134 FaultLoggerdSystemTest::StartCrasherLoop(3);
3135 std::string procCMD = "dumpcatcher -p " + std::to_string(FaultLoggerdSystemTest::loopAppPid) + " -t "+
3136 std::to_string(FaultLoggerdSystemTest::loopAppPid);
3137 string procDumpLog = FaultLoggerdSystemTest::ProcessDumpCommands(procCMD);
3138 GTEST_LOG_(INFO) << "procDumpLog: " << procDumpLog;
3139 int count = 0;
3140 string log[] = {"", "name:/data/crasher", "Name:crasher_c", "#00", "/data/crasher"};
3141 log[0] = log[0] + std::to_string(FaultLoggerdSystemTest::loopAppPid);
3142 string::size_type idx;
3143 for (int i = 0; i < 5; i++) {
3144 idx = procDumpLog.find(log[i]);
3145 if (idx != string::npos) {
3146 GTEST_LOG_(INFO) << log[i];
3147 count++;
3148 }
3149 }
3150 EXPECT_EQ(count, 5) << "FaultLoggerdSystemTest041 Failed";
3151 FaultLoggerdSystemTest::KillCrasherLoopForSomeCase(3);
3152 GTEST_LOG_(INFO) << "FaultLoggerdSystemTest041: end.";
3153 }
3154
3155 /**
3156 * @tc.name: FaultLoggerdSystemTest042
3157 * @tc.desc: test dumpcatcher command: dumpcatcher -p apppid -t apptid
3158 * @tc.type: FUNC
3159 */
3160 HWTEST_F (FaultLoggerdSystemTest, FaultLoggerdSystemTest042, TestSize.Level2)
3161 {
3162 GTEST_LOG_(INFO) << "FaultLoggerdSystemTest042: start uid:" << getuid();
3163 FaultLoggerdSystemTest::StartCrasherLoop(3);
3164 int tid = std::stoi(FaultLoggerdSystemTest::appTid[0]);
3165 if (FaultLoggerdSystemTest::loopAppPid == std::stoi(FaultLoggerdSystemTest::appTid[0])) {
3166 tid = std::stoi(FaultLoggerdSystemTest::appTid[1]);
3167 }
3168 std::string procCMD = "dumpcatcher -p " + std::to_string(FaultLoggerdSystemTest::loopAppPid) + " -t "+
3169 std::to_string(tid);
3170 string procDumpLog = FaultLoggerdSystemTest::ProcessDumpCommands(procCMD);
3171 GTEST_LOG_(INFO) << "procDumpLog: " << procDumpLog;
3172 int count = 0;
3173 string log[] = {"", "name:/data/crasher", "Name:SubTestThread", "#00", "/data/crasher"};
3174 log[0] = log[0] + std::to_string(FaultLoggerdSystemTest::loopAppPid);
3175 string::size_type idx;
3176 for (int i = 0; i < 5; i++) {
3177 idx = procDumpLog.find(log[i]);
3178 if (idx != string::npos) {
3179 GTEST_LOG_(INFO) << log[i];
3180 count++;
3181 }
3182 }
3183 EXPECT_EQ(count, 5) << "FaultLoggerdSystemTest042 Failed";
3184 FaultLoggerdSystemTest::KillCrasherLoopForSomeCase(3);
3185 GTEST_LOG_(INFO) << "FaultLoggerdSystemTest042: end.";
3186 }
3187
3188 /**
3189 * @tc.name: FaultLoggerdSystemTest043
3190 * @tc.desc: test dumpcatcher command: -p systempid
3191 * @tc.type: FUNC
3192 */
3193 HWTEST_F (FaultLoggerdSystemTest, FaultLoggerdSystemTest043, TestSize.Level2)
3194 {
3195 GTEST_LOG_(INFO) << "FaultLoggerdSystemTest043: start.";
3196 FaultLoggerdSystemTest::StartCrasherLoop(1);
3197 FaultLoggerdSystemTest::StartCrasherLoop(3);
3198 std::string procCMD = "dumpcatcher -p " + std::to_string(FaultLoggerdSystemTest::loopSysPid) + " -t "
3199 + std::to_string(FaultLoggerdSystemTest::loopSysPid);
3200 string procDumpLog = FaultLoggerdSystemTest::ProcessDumpCommands(procCMD);
3201 GTEST_LOG_(INFO) << "procDumpLog: " << procDumpLog;
3202 int count = 0;
3203 string log[] = {"Failed"};
3204 string::size_type idx;
3205 for (int i = 0; i < 1; i++) {
3206 idx = procDumpLog.find(log[i]);
3207 if (idx != string::npos) {
3208 GTEST_LOG_(INFO) << count;
3209 GTEST_LOG_(INFO) << log[i];
3210 count++;
3211 }
3212 }
3213 EXPECT_EQ(count, 1) << "FaultLoggerdSystemTest043 Failed";
3214 FaultLoggerdSystemTest::KillCrasherLoopForSomeCase(1);
3215 FaultLoggerdSystemTest::KillCrasherLoopForSomeCase(3);
3216 GTEST_LOG_(INFO) << "FaultLoggerdSystemTest043: end.";
3217 }
3218
3219 /**
3220 * @tc.name: FaultLoggerdSystemTest0109
3221 * @tc.desc: test dumpcatcher command: -p rootpid
3222 * @tc.type: FUNC
3223 */
3224 HWTEST_F (FaultLoggerdSystemTest, FaultLoggerdSystemTest0109, TestSize.Level2)
3225 {
3226 GTEST_LOG_(INFO) << "FaultLoggerdSystemTest0109: start.";
3227 FaultLoggerdSystemTest::StartCrasherLoop(2);
3228 FaultLoggerdSystemTest::StartCrasherLoop(3);
3229 std::string procCMD = "dumpcatcher -p " + std::to_string(FaultLoggerdSystemTest::loopRootPid) + " -t "
3230 + std::to_string(FaultLoggerdSystemTest::loopRootPid);
3231 string procDumpLog = FaultLoggerdSystemTest::ProcessDumpCommands(procCMD);
3232 GTEST_LOG_(INFO) << "procDumpLog: " << procDumpLog;
3233 int count = 0;
3234 string log[] = {"Failed"};
3235 string::size_type idx;
3236 for (int i = 0; i < 1; i++) {
3237 idx = procDumpLog.find(log[i]);
3238 if (idx != string::npos) {
3239 GTEST_LOG_(INFO) << count;
3240 GTEST_LOG_(INFO) << log[i];
3241 count++;
3242 }
3243 }
3244 EXPECT_EQ(count, 1) << "FaultLoggerdSystemTest0109 Failed";
3245 FaultLoggerdSystemTest::KillCrasherLoopForSomeCase(2);
3246 FaultLoggerdSystemTest::KillCrasherLoopForSomeCase(3);
3247 GTEST_LOG_(INFO) << "FaultLoggerdSystemTest0109: end.";
3248 }
3249
3250 /**
3251 * @tc.name: FaultLoggerdSystemTest044
3252 * @tc.desc: test dumpcatcher command: -p 9999 -t apppid
3253 * @tc.type: FUNC
3254 */
3255 HWTEST_F (FaultLoggerdSystemTest, FaultLoggerdSystemTest044, TestSize.Level2)
3256 {
3257 GTEST_LOG_(INFO) << "FaultLoggerdSystemTest044: start.";
3258 FaultLoggerdSystemTest::StartCrasherLoop(3);
3259 std::string procCMD = "dumpcatcher -p 9999 -t "+ std::to_string(FaultLoggerdSystemTest::loopAppPid);
3260 string procDumpLog = FaultLoggerdSystemTest::ProcessDumpCommands(procCMD);
3261 GTEST_LOG_(INFO) << "procDumpLog: " << procDumpLog;
3262 int count = 0;
3263 string log[] = {"Failed"};
3264 string::size_type idx;
3265 for (int i = 0; i < 1; i++) {
3266 idx = procDumpLog.find(log[i]);
3267 if (idx != string::npos) {
3268 GTEST_LOG_(INFO) << count;
3269 GTEST_LOG_(INFO) << log[i];
3270 count++;
3271 }
3272 }
3273 EXPECT_EQ(count, 1) << "FaultLoggerdSystemTest044 Failed";
3274 FaultLoggerdSystemTest::KillCrasherLoopForSomeCase(3);
3275 GTEST_LOG_(INFO) << "FaultLoggerdSystemTest044: end.";
3276 }
3277
3278 /**
3279 * @tc.name: FaultLoggerdSystemTest045
3280 * @tc.desc: test dumpcatcher command: -p apppid -t 9999
3281 * @tc.type: FUNC
3282 */
3283 HWTEST_F (FaultLoggerdSystemTest, FaultLoggerdSystemTest045, TestSize.Level2)
3284 {
3285 GTEST_LOG_(INFO) << "FaultLoggerdSystemTest045: start.";
3286 FaultLoggerdSystemTest::StartCrasherLoop(3);
3287 std::string procCMD = "dumpcatcher -p " + std::to_string(FaultLoggerdSystemTest::loopAppPid) + " -t 9999";
3288 string procDumpLog = FaultLoggerdSystemTest::ProcessDumpCommands(procCMD);
3289 GTEST_LOG_(INFO) << "procDumpLog: " << procDumpLog;
3290 int count = 0;
3291 string log[] = {"Failed"};
3292 string::size_type idx;
3293 for (int i = 0; i < 1; i++) {
3294 idx = procDumpLog.find(log[i]);
3295 if (idx != string::npos) {
3296 GTEST_LOG_(INFO) << count;
3297 GTEST_LOG_(INFO) << log[i];
3298 count++;
3299 }
3300 }
3301 EXPECT_EQ(count, 1) << "FaultLoggerdSystemTest045 Failed";
3302 FaultLoggerdSystemTest::KillCrasherLoopForSomeCase(3);
3303 GTEST_LOG_(INFO) << "FaultLoggerdSystemTest045: end.";
3304 }
3305
3306 /**
3307 * @tc.name: FaultLoggerdSystemTest046
3308 * @tc.desc: test dumpcatcher command: -p apppid -t systempid
3309 * @tc.type: FUNC
3310 */
3311 HWTEST_F (FaultLoggerdSystemTest, FaultLoggerdSystemTest046, TestSize.Level2)
3312 {
3313 GTEST_LOG_(INFO) << "FaultLoggerdSystemTest046: start.";
3314 FaultLoggerdSystemTest::StartCrasherLoop(1);
3315 FaultLoggerdSystemTest::StartCrasherLoop(3);
3316 std::string procCMD = "dumpcatcher -p " + std::to_string(FaultLoggerdSystemTest::loopAppPid) + " -t "
3317 + std::to_string(FaultLoggerdSystemTest::loopSysPid);
3318 string procDumpLog = FaultLoggerdSystemTest::ProcessDumpCommands(procCMD);
3319 GTEST_LOG_(INFO) << "procDumpLog: " << procDumpLog;
3320 int count = 0;
3321 string log[] = {"Failed"};
3322 string::size_type idx;
3323 for (int i = 0; i < 1; i++) {
3324 idx = procDumpLog.find(log[i]);
3325 if (idx != string::npos) {
3326 GTEST_LOG_(INFO) << count;
3327 GTEST_LOG_(INFO) << log[i];
3328 count++;
3329 }
3330 }
3331 EXPECT_EQ(count, 1) << "FaultLoggerdSystemTest046 Failed";
3332 FaultLoggerdSystemTest::KillCrasherLoopForSomeCase(1);
3333 FaultLoggerdSystemTest::KillCrasherLoopForSomeCase(3);
3334 GTEST_LOG_(INFO) << "FaultLoggerdSystemTest046: end.";
3335 }
3336
3337 /**
3338 * @tc.name: FaultLoggerdSystemTest047
3339 * @tc.desc: test dumpcatcher command: -p systempid -t apppid
3340 * @tc.type: FUNC
3341 */
3342 HWTEST_F (FaultLoggerdSystemTest, FaultLoggerdSystemTest047, TestSize.Level2)
3343 {
3344 GTEST_LOG_(INFO) << "FaultLoggerdSystemTest047: start.";
3345 FaultLoggerdSystemTest::StartCrasherLoop(1);
3346 FaultLoggerdSystemTest::StartCrasherLoop(3);
3347 std::string procCMD = "dumpcatcher -p " + std::to_string(FaultLoggerdSystemTest::loopSysPid) + " -t "
3348 + std::to_string(FaultLoggerdSystemTest::loopAppPid);
3349 string procDumpLog = FaultLoggerdSystemTest::ProcessDumpCommands(procCMD);
3350 GTEST_LOG_(INFO) << "procDumpLog: " << procDumpLog;
3351 int count = 0;
3352 string log[] = {"Failed"};
3353 string::size_type idx;
3354 for (int i = 0; i < 1; i++) {
3355 idx = procDumpLog.find(log[i]);
3356 if (idx != string::npos) {
3357 GTEST_LOG_(INFO) << count;
3358 GTEST_LOG_(INFO) << log[i];
3359 count++;
3360 }
3361 }
3362 EXPECT_EQ(count, 1) << "FaultLoggerdSystemTest047 Failed";
3363 FaultLoggerdSystemTest::KillCrasherLoopForSomeCase(1);
3364 FaultLoggerdSystemTest::KillCrasherLoopForSomeCase(3);
3365 GTEST_LOG_(INFO) << "FaultLoggerdSystemTest047: end.";
3366 }
3367
3368 /**
3369 * @tc.name: FaultLoggerdSystemTest048
3370 * @tc.desc: test dumpcatcher command: -p -t apppid
3371 * @tc.type: FUNC
3372 */
3373 HWTEST_F (FaultLoggerdSystemTest, FaultLoggerdSystemTest048, TestSize.Level2)
3374 {
3375 GTEST_LOG_(INFO) << "FaultLoggerdSystemTest048: start.";
3376 FaultLoggerdSystemTest::StartCrasherLoop(3);
3377 std::string procCMD = "dumpcatcher -p -t " + std::to_string(FaultLoggerdSystemTest::loopAppPid);
3378 string procDumpLog = FaultLoggerdSystemTest::ProcessDumpCommands(procCMD);
3379 GTEST_LOG_(INFO) << "procDumpLog: " << procDumpLog;
3380 int count = 0;
3381 string log[] = {"Failed"};
3382 string::size_type idx;
3383 for (int i = 0; i < 1; i++) {
3384 idx = procDumpLog.find(log[i]);
3385 if (idx != string::npos) {
3386 GTEST_LOG_(INFO) << count;
3387 GTEST_LOG_(INFO) << log[i];
3388 count++;
3389 }
3390 }
3391 EXPECT_EQ(count, 1) << "FaultLoggerdSystemTest048 Failed";
3392 FaultLoggerdSystemTest::KillCrasherLoopForSomeCase(3);
3393 GTEST_LOG_(INFO) << "FaultLoggerdSystemTest048: end.";
3394 }
3395
3396 /**
3397 * @tc.name: FaultLoggerdSystemTest049
3398 * @tc.desc: test dumpcatcher command: -p apppid -t
3399 * @tc.type: FUNC
3400 */
3401 HWTEST_F (FaultLoggerdSystemTest, FaultLoggerdSystemTest049, TestSize.Level2)
3402 {
3403 GTEST_LOG_(INFO) << "FaultLoggerdSystemTest049: start.";
3404 FaultLoggerdSystemTest::StartCrasherLoop(3);
3405 std::string procCMD = "dumpcatcher -p " + std::to_string(FaultLoggerdSystemTest::loopAppPid) + " -t ";
3406 string procDumpLog = FaultLoggerdSystemTest::ProcessDumpCommands(procCMD);
3407 GTEST_LOG_(INFO) << "procDumpLog: " << procDumpLog;
3408 int count = 0;
3409 string log[] = {"Usage:", "dump the stacktrace"};
3410 string::size_type idx;
3411 for (int i = 0; i < 2; i++) {
3412 idx = procDumpLog.find(log[i]);
3413 if (idx != string::npos) {
3414 GTEST_LOG_(INFO) << count;
3415 GTEST_LOG_(INFO) << log[i];
3416 count++;
3417 }
3418 }
3419 EXPECT_EQ(count, 2) << "FaultLoggerdSystemTest049 Failed";
3420 FaultLoggerdSystemTest::KillCrasherLoopForSomeCase(3);
3421 GTEST_LOG_(INFO) << "FaultLoggerdSystemTest049: end.";
3422 }
3423
3424 /**
3425 * @tc.name: FaultLoggerdSystemTest050
3426 * @tc.desc: test dumpcatcher command: -p -11 -t apppid
3427 * @tc.type: FUNC
3428 */
3429 HWTEST_F (FaultLoggerdSystemTest, FaultLoggerdSystemTest050, TestSize.Level2)
3430 {
3431 GTEST_LOG_(INFO) << "FaultLoggerdSystemTest050: start.";
3432 FaultLoggerdSystemTest::StartCrasherLoop(3);
3433 std::string procCMD = "dumpcatcher -p -11 -t " + std::to_string(FaultLoggerdSystemTest::loopAppPid);
3434 string procDumpLog = FaultLoggerdSystemTest::ProcessDumpCommands(procCMD);
3435 GTEST_LOG_(INFO) << "procDumpLog: " << procDumpLog;
3436 int count = 0;
3437 string log[] = {"Failed"};
3438 string::size_type idx;
3439 for (int i = 0; i < 1; i++) {
3440 idx = procDumpLog.find(log[i]);
3441 if (idx != string::npos) {
3442 GTEST_LOG_(INFO) << count;
3443 GTEST_LOG_(INFO) << log[i];
3444 count++;
3445 }
3446 }
3447 EXPECT_EQ(count, 1) << "FaultLoggerdSystemTest050 Failed";
3448 FaultLoggerdSystemTest::KillCrasherLoopForSomeCase(3);
3449 GTEST_LOG_(INFO) << "FaultLoggerdSystemTest050: end.";
3450 }
3451
3452 /**
3453 * @tc.name: FaultLoggerdSystemTest051
3454 * @tc.desc: test dumpcatcher command: -p apppid -t -11
3455 * @tc.type: FUNC
3456 */
3457 HWTEST_F (FaultLoggerdSystemTest, FaultLoggerdSystemTest051, TestSize.Level2)
3458 {
3459 GTEST_LOG_(INFO) << "FaultLoggerdSystemTest051: start.";
3460 FaultLoggerdSystemTest::StartCrasherLoop(3);
3461 std::string procCMD = "dumpcatcher -p " + std::to_string(FaultLoggerdSystemTest::loopAppPid) + " -t -11";
3462 string procDumpLog = FaultLoggerdSystemTest::ProcessDumpCommands(procCMD);
3463 GTEST_LOG_(INFO) << "procDumpLog: " << procDumpLog;
3464 int count = 0;
3465 string log[] = {"Failed"};
3466 string::size_type idx;
3467 for (int i = 0; i < 1; i++) {
3468 idx = procDumpLog.find(log[i]);
3469 if (idx != string::npos) {
3470 GTEST_LOG_(INFO) << count;
3471 GTEST_LOG_(INFO) << log[i];
3472 count++;
3473 }
3474 }
3475 EXPECT_EQ(count, 1) << "FaultLoggerdSystemTest051 Failed";
3476 FaultLoggerdSystemTest::KillCrasherLoopForSomeCase(3);
3477 GTEST_LOG_(INFO) << "FaultLoggerdSystemTest051: end.";
3478 }
3479
3480 /**
3481 * @tc.name: FaultLoggerdSystemTest052
3482 * @tc.desc: test dumpcatcher command: -p systempid
3483 * @tc.type: FUNC
3484 */
3485 HWTEST_F (FaultLoggerdSystemTest, FaultLoggerdSystemTest052, TestSize.Level2)
3486 {
3487 GTEST_LOG_(INFO) << "FaultLoggerdSystemTest052: start.";
3488 FaultLoggerdSystemTest::StartCrasherLoop(1);
3489 int uidSetting = BMS_UID;
3490 setuid(uidSetting);
3491 std::string procCMD = "dumpcatcher -p " + std::to_string(FaultLoggerdSystemTest::loopSysPid);
3492 string procDumpLog = FaultLoggerdSystemTest::ProcessDumpCommands(procCMD);
3493 GTEST_LOG_(INFO) << "procDumpLog: " << procDumpLog;
3494 int count = 0;
3495 string log[] = {"", "Name:crasher", "Name:SubTestThread", "#00", "/data/crasher"};
3496 log[0] = log[0] + std::to_string(FaultLoggerdSystemTest::loopSysPid);
3497 string::size_type idx;
3498 for (int i = 0; i < 5; i++) {
3499 idx = procDumpLog.find(log[i]);
3500 if (idx != string::npos) {
3501 GTEST_LOG_(INFO) << log[i];
3502 count++;
3503 }
3504 }
3505 int otheruid =OTHER_UID;
3506 setuid(otheruid);
3507 EXPECT_EQ(count, 5) << "FaultLoggerdSystemTest052 Failed";
3508 FaultLoggerdSystemTest::KillCrasherLoopForSomeCase(1);
3509 GTEST_LOG_(INFO) << "FaultLoggerdSystemTest052: end.";
3510 }
3511
3512 /**
3513 * @tc.name: FaultLoggerdSystemTest0105
3514 * @tc.desc: test dumpcatcher command: -p rootpid
3515 * @tc.type: FUNC
3516 */
3517 HWTEST_F (FaultLoggerdSystemTest, FaultLoggerdSystemTest0105, TestSize.Level2)
3518 {
3519 GTEST_LOG_(INFO) << "FaultLoggerdSystemTest0105: start.";
3520 FaultLoggerdSystemTest::StartCrasherLoop(2);
3521 int uidSetting = 0;
3522 setuid(uidSetting);
3523 std::string procCMD = "dumpcatcher -p " + std::to_string(FaultLoggerdSystemTest::loopRootPid);
3524 string procDumpLog = FaultLoggerdSystemTest::ProcessDumpCommands(procCMD);
3525 GTEST_LOG_(INFO) << "procDumpLog: " << procDumpLog;
3526 int count = 0;
3527 string log[] = {"", "Name:crasher", "Name:SubTestThread", "#00", "/data/crasher"};
3528 log[0] = log[0] + std::to_string(FaultLoggerdSystemTest::loopRootPid);
3529 string::size_type idx;
3530 for (int i = 0; i < 5; i++) {
3531 idx = procDumpLog.find(log[i]);
3532 if (idx != string::npos) {
3533 GTEST_LOG_(INFO) << log[i];
3534 count++;
3535 }
3536 }
3537 int otheruid =OTHER_UID;
3538 setuid(otheruid);
3539 EXPECT_EQ(count, 5) << "FaultLoggerdSystemTest0105 Failed";
3540 FaultLoggerdSystemTest::KillCrasherLoopForSomeCase(2);
3541 GTEST_LOG_(INFO) << "FaultLoggerdSystemTest0105: end.";
3542 }
3543
3544 /**
3545 * @tc.name: FaultLoggerdSystemTest053
3546 * @tc.desc: test dumpcatcher command: -p apppid
3547 * @tc.type: FUNC
3548 */
3549 HWTEST_F (FaultLoggerdSystemTest, FaultLoggerdSystemTest053, TestSize.Level2)
3550 {
3551 GTEST_LOG_(INFO) << "FaultLoggerdSystemTest053: start.";
3552 FaultLoggerdSystemTest::StartCrasherLoop(3);
3553 FaultLoggerdSystemTest::StartCrasherLoop(1);
3554 int uidSetting = BMS_UID;
3555 setuid(uidSetting);
3556 std::string procCMD = "dumpcatcher -p " + std::to_string(FaultLoggerdSystemTest::loopAppPid);
3557 string procDumpLog = FaultLoggerdSystemTest::ProcessDumpCommands(procCMD);
3558 GTEST_LOG_(INFO) << "procDumpLog: " << procDumpLog;
3559 int count = 0;
3560 string log[] = {"", "Name:crasher", "Name:SubTestThread", "#00", "/data/crasher"};
3561 log[0] = log[0] + std::to_string(FaultLoggerdSystemTest::loopAppPid);
3562 string::size_type idx;
3563 for (int i = 0; i < 5; i++) {
3564 idx = procDumpLog.find(log[i]);
3565 if (idx != string::npos) {
3566 GTEST_LOG_(INFO) << log[i];
3567 count++;
3568 }
3569 }
3570 EXPECT_EQ(count, 5) << "FaultLoggerdSystemTest053 Failed";
3571 FaultLoggerdSystemTest::KillCrasherLoopForSomeCase(3);
3572 FaultLoggerdSystemTest::KillCrasherLoopForSomeCase(1);
3573 GTEST_LOG_(INFO) << "FaultLoggerdSystemTest053: end.";
3574 }
3575
3576 /**
3577 * @tc.name: FaultLoggerdSystemTest0106
3578 * @tc.desc: test dumpcatcher command: -p apppid
3579 * @tc.type: FUNC
3580 */
3581 HWTEST_F (FaultLoggerdSystemTest, FaultLoggerdSystemTest0106, TestSize.Level2)
3582 {
3583 GTEST_LOG_(INFO) << "FaultLoggerdSystemTest0106: start.";
3584 FaultLoggerdSystemTest::StartCrasherLoop(2);
3585 FaultLoggerdSystemTest::StartCrasherLoop(1);
3586 int uidSetting = BMS_UID;
3587 setuid(uidSetting);
3588 std::string procCMD = "dumpcatcher -p " + std::to_string(FaultLoggerdSystemTest::loopRootPid);
3589 string procDumpLog = FaultLoggerdSystemTest::ProcessDumpCommands(procCMD);
3590 GTEST_LOG_(INFO) << "procDumpLog: " << procDumpLog;
3591 int count = 0;
3592 string log[] = {"", "Name:crasher", "Name:SubTestThread", "#00", "/data/crasher"};
3593 log[0] = log[0] + std::to_string(FaultLoggerdSystemTest::loopRootPid);
3594 string::size_type idx;
3595 for (int i = 0; i < 5; i++) {
3596 idx = procDumpLog.find(log[i]);
3597 if (idx != string::npos) {
3598 GTEST_LOG_(INFO) << log[i];
3599 count++;
3600 }
3601 }
3602 EXPECT_EQ(count, 5) << "FaultLoggerdSystemTest0106 Failed";
3603 FaultLoggerdSystemTest::KillCrasherLoopForSomeCase(2);
3604 FaultLoggerdSystemTest::KillCrasherLoopForSomeCase(1);
3605 GTEST_LOG_(INFO) << "FaultLoggerdSystemTest0106: end.";
3606 }
3607
3608 /**
3609 * @tc.name: FaultLoggerdSystemTest0107
3610 * @tc.desc: test dumpcatcher command: -p apppid
3611 * @tc.type: FUNC
3612 */
3613 HWTEST_F (FaultLoggerdSystemTest, FaultLoggerdSystemTest0107, TestSize.Level2)
3614 {
3615 GTEST_LOG_(INFO) << "FaultLoggerdSystemTest0107: start.";
3616 FaultLoggerdSystemTest::StartCrasherLoop(3);
3617 FaultLoggerdSystemTest::StartCrasherLoop(2);
3618 int uidSetting = 0;
3619 setuid(uidSetting);
3620 std::string procCMD = "dumpcatcher -p " + std::to_string(FaultLoggerdSystemTest::loopAppPid);
3621 string procDumpLog = FaultLoggerdSystemTest::ProcessDumpCommands(procCMD);
3622 GTEST_LOG_(INFO) << "procDumpLog: " << procDumpLog;
3623 int count = 0;
3624 int apptid1 = std::stoi(appTid[0]);
3625 int apptid2 = std::stoi(appTid[1]);
3626 string log[] = {"", "Name:crasher", "Name:SubTestThread", "#00", "/data/crasher", ""};
3627 log[0] = log[0] + std::to_string(apptid1);
3628 log[5] = log[5] + std::to_string(apptid2);
3629 string::size_type idx;
3630 for (int i = 0; i < 6; i++) {
3631 idx = procDumpLog.find(log[i]);
3632 if (idx != string::npos) {
3633 GTEST_LOG_(INFO) << log[i];
3634 count++;
3635 }
3636 }
3637 EXPECT_EQ(count, 6) << "FaultLoggerdSystemTest0107 Failed";
3638 FaultLoggerdSystemTest::KillCrasherLoopForSomeCase(3);
3639 FaultLoggerdSystemTest::KillCrasherLoopForSomeCase(2);
3640 GTEST_LOG_(INFO) << "FaultLoggerdSystemTest0107: end.";
3641 }
3642
3643 /**
3644 * @tc.name: FaultLoggerdSystemTest0108
3645 * @tc.desc: test dumpcatcher command: -p sytempid
3646 * @tc.type: FUNC
3647 */
3648 HWTEST_F (FaultLoggerdSystemTest, FaultLoggerdSystemTest0108, TestSize.Level2)
3649 {
3650 GTEST_LOG_(INFO) << "FaultLoggerdSystemTest0108: start.";
3651 FaultLoggerdSystemTest::StartCrasherLoop(1);
3652 FaultLoggerdSystemTest::StartCrasherLoop(2);
3653 int uidSetting = 0;
3654 setuid(uidSetting);
3655 std::string procCMD = "dumpcatcher -p " + std::to_string(FaultLoggerdSystemTest::loopSysPid);
3656 string procDumpLog = FaultLoggerdSystemTest::ProcessDumpCommands(procCMD);
3657 GTEST_LOG_(INFO) << "procDumpLog: " << procDumpLog;
3658 int count = 0;
3659 int systid1 = std::stoi(sysTid[0]);
3660 int systid2 = std::stoi(sysTid[1]);
3661 string log[] = {"", "Name:crasher", "Name:SubTestThread", "#00", "/data/crasher", ""};
3662 log[0] = log[0] + std::to_string(systid1);
3663 log[5] = log[5] + std::to_string(systid2);
3664 string::size_type idx;
3665 for (int i = 0; i < 6; i++) {
3666 idx = procDumpLog.find(log[i]);
3667 if (idx != string::npos) {
3668 GTEST_LOG_(INFO) << log[i];
3669 count++;
3670 }
3671 }
3672 int otheruid = OTHER_UID;
3673 setuid(otheruid);
3674 EXPECT_EQ(count, 6) << "FaultLoggerdSystemTest0108 Failed";
3675 FaultLoggerdSystemTest::KillCrasherLoopForSomeCase(1);
3676 FaultLoggerdSystemTest::KillCrasherLoopForSomeCase(2);
3677 GTEST_LOG_(INFO) << "FaultLoggerdSystemTest0108: end.";
3678 }
3679
3680 /**
3681 * @tc.name: FaultLoggerdSystemTest054
3682 * @tc.desc: test dumpcatcher command: -p apppid -t rootpid
3683 * @tc.type: FUNC
3684 */
3685 HWTEST_F (FaultLoggerdSystemTest, FaultLoggerdSystemTest054, TestSize.Level2)
3686 {
3687 GTEST_LOG_(INFO) << "FaultLoggerdSystemTest054: start.";
3688 FaultLoggerdSystemTest::StartCrasherLoop(2);
3689 FaultLoggerdSystemTest::StartCrasherLoop(3);
3690 std::string procCMD = "dumpcatcher -p " + std::to_string(FaultLoggerdSystemTest::loopAppPid) + " -t " +
3691 std::to_string(FaultLoggerdSystemTest::loopRootPid);
3692 string procDumpLog = FaultLoggerdSystemTest::ProcessDumpCommands(procCMD);
3693 GTEST_LOG_(INFO) << "procDumpLog: " << procDumpLog;
3694 int count = 0;
3695 string log[] = {"Failed"};
3696 string::size_type idx;
3697 for (int i = 0; i < 1; i++) {
3698 idx = procDumpLog.find(log[i]);
3699 if (idx != string::npos) {
3700 GTEST_LOG_(INFO) << count;
3701 GTEST_LOG_(INFO) << log[i];
3702 count++;
3703 }
3704 }
3705 EXPECT_EQ(count, 1) << "FaultLoggerdSystemTest054 Failed";
3706 FaultLoggerdSystemTest::KillCrasherLoopForSomeCase(2);
3707 FaultLoggerdSystemTest::KillCrasherLoopForSomeCase(3);
3708 GTEST_LOG_(INFO) << "FaultLoggerdSystemTest054: end.";
3709 }
3710
3711 /**
3712 * @tc.name: FaultLoggerdSystemTest055
3713 * @tc.desc: test dumpcatcher command: -p rootpid, -t apppid
3714 * @tc.type: FUNC
3715 */
3716 HWTEST_F (FaultLoggerdSystemTest, FaultLoggerdSystemTest055, TestSize.Level2)
3717 {
3718 GTEST_LOG_(INFO) << "FaultLoggerdSystemTest055: start.";
3719 FaultLoggerdSystemTest::StartCrasherLoop(2);
3720 FaultLoggerdSystemTest::StartCrasherLoop(3);
3721 std::string procCMD = "dumpcatcher -p " + std::to_string(FaultLoggerdSystemTest::loopRootPid) + " -t " +
3722 std::to_string(FaultLoggerdSystemTest::loopAppPid);
3723 string procDumpLog = FaultLoggerdSystemTest::ProcessDumpCommands(procCMD);
3724 GTEST_LOG_(INFO) << "procDumpLog: " << procDumpLog;
3725 int count = 0;
3726 string log[] = {"Failed"};
3727 string::size_type idx;
3728 for (int i = 0; i < 1; i++) {
3729 idx = procDumpLog.find(log[i]);
3730 if (idx != string::npos) {
3731 GTEST_LOG_(INFO) << count;
3732 GTEST_LOG_(INFO) << log[i];
3733 count++;
3734 }
3735 }
3736 EXPECT_EQ(count, 1) << "FaultLoggerdSystemTest055 Failed";
3737 FaultLoggerdSystemTest::KillCrasherLoopForSomeCase(2);
3738 FaultLoggerdSystemTest::KillCrasherLoopForSomeCase(3);
3739 GTEST_LOG_(INFO) << "FaultLoggerdSystemTest055: end.";
3740 }
3741
3742 /**
3743 * @tc.name: FaultLoggerdSystemTest0114
3744 * @tc.desc: test dumpcatcher command: -p pid-max, -t threads_max
3745 * @tc.type: FUNC
3746 */
3747 HWTEST_F (FaultLoggerdSystemTest, FaultLoggerdSystemTest0114, TestSize.Level2)
3748 {
3749 GTEST_LOG_(INFO) << "FaultLoggerdSystemTest0114: start.";
3750 FaultLoggerdSystemTest::StartCrasherLoop(3);
3751 std::string procCMD = "dumpcatcher -p " + GetPidMax() + " -t " + GetTidMax();
3752 string procDumpLog = FaultLoggerdSystemTest::ProcessDumpCommands(procCMD);
3753 GTEST_LOG_(INFO) << "procDumpLog: " << procDumpLog;
3754 int count = 0;
3755 string log[] = {"Failed"};
3756 string::size_type idx;
3757 for (int i = 0; i < 1; i++) {
3758 idx = procDumpLog.find(log[i]);
3759 if (idx != string::npos) {
3760 GTEST_LOG_(INFO) << count;
3761 GTEST_LOG_(INFO) << log[i];
3762 count++;
3763 }
3764 }
3765 EXPECT_EQ(count, 1) << "FaultLoggerdSystemTest0114 Failed";
3766 FaultLoggerdSystemTest::KillCrasherLoopForSomeCase(3);
3767 GTEST_LOG_(INFO) << "FaultLoggerdSystemTest0114: end.";
3768 }
3769
3770 /**
3771 * @tc.name: FaultLoggerdSystemTest0115
3772 * @tc.desc: test dumpcatcher command: -p 65535, -t 65535
3773 * @tc.type: FUNC
3774 */
3775 HWTEST_F (FaultLoggerdSystemTest, FaultLoggerdSystemTest0115, TestSize.Level2)
3776 {
3777 GTEST_LOG_(INFO) << "FaultLoggerdSystemTest0115: start.";
3778 FaultLoggerdSystemTest::StartCrasherLoop(3);
3779 std::string procCMD = "dumpcatcher -p 65535 -t 65535";
3780 string procDumpLog = FaultLoggerdSystemTest::ProcessDumpCommands(procCMD);
3781 GTEST_LOG_(INFO) << "procDumpLog: " << procDumpLog;
3782 int count = 0;
3783 string log[] = {"Failed"};
3784 string::size_type idx;
3785 for (int i = 0; i < 1; i++) {
3786 idx = procDumpLog.find(log[i]);
3787 if (idx != string::npos) {
3788 GTEST_LOG_(INFO) << count;
3789 GTEST_LOG_(INFO) << log[i];
3790 count++;
3791 }
3792 }
3793 EXPECT_EQ(count, 1) << "FaultLoggerdSystemTest0115 Failed";
3794 FaultLoggerdSystemTest::KillCrasherLoopForSomeCase(3);
3795 GTEST_LOG_(INFO) << "FaultLoggerdSystemTest0115: end.";
3796 }
3797
3798 /**
3799 * @tc.name: FaultLoggerdSystemTest0116
3800 * @tc.desc: test dumpcatcher command: -p 65536, -t 65536
3801 * @tc.type: FUNC
3802 */
3803 HWTEST_F (FaultLoggerdSystemTest, FaultLoggerdSystemTest0116, TestSize.Level2)
3804 {
3805 GTEST_LOG_(INFO) << "FaultLoggerdSystemTest0116: start.";
3806 FaultLoggerdSystemTest::StartCrasherLoop(3);
3807 std::string procCMD = "dumpcatcher -p 65536 -t 65536";
3808 string procDumpLog = FaultLoggerdSystemTest::ProcessDumpCommands(procCMD);
3809 GTEST_LOG_(INFO) << "procDumpLog: " << procDumpLog;
3810 int count = 0;
3811 string log[] = {"Failed"};
3812 string::size_type idx;
3813 for (int i = 0; i < 1; i++) {
3814 idx = procDumpLog.find(log[i]);
3815 if (idx != string::npos) {
3816 GTEST_LOG_(INFO) << count;
3817 GTEST_LOG_(INFO) << log[i];
3818 count++;
3819 }
3820 }
3821 EXPECT_EQ(count, 1) << "FaultLoggerdSystemTest0116 Failed";
3822 FaultLoggerdSystemTest::KillCrasherLoopForSomeCase(3);
3823 GTEST_LOG_(INFO) << "FaultLoggerdSystemTest0116: end.";
3824 }
3825
3826 /**
3827 * @tc.name: FaultLoggerdSystemTest0117
3828 * @tc.desc: test dumpcatcher command: -p 65534, -t 65534
3829 * @tc.type: FUNC
3830 */
3831 HWTEST_F (FaultLoggerdSystemTest, FaultLoggerdSystemTest0117, TestSize.Level2)
3832 {
3833 GTEST_LOG_(INFO) << "FaultLoggerdSystemTest117: start.";
3834 FaultLoggerdSystemTest::StartCrasherLoop(3);
3835 std::string procCMD = "dumpcatcher -p 65534 -t 65534";
3836 string procDumpLog = FaultLoggerdSystemTest::ProcessDumpCommands(procCMD);
3837 GTEST_LOG_(INFO) << "procDumpLog: " << procDumpLog;
3838 int count = 0;
3839 string log[] = {"Failed"};
3840 string::size_type idx;
3841 for (int i = 0; i < 1; i++) {
3842 idx = procDumpLog.find(log[i]);
3843 if (idx != string::npos) {
3844 GTEST_LOG_(INFO) << count;
3845 GTEST_LOG_(INFO) << log[i];
3846 count++;
3847 }
3848 }
3849 EXPECT_EQ(count, 1) << "FaultLoggerdSystemTest0117 Failed";
3850 FaultLoggerdSystemTest::KillCrasherLoopForSomeCase(3);
3851 GTEST_LOG_(INFO) << "FaultLoggerdSystemTest0117: end.";
3852 }
3853
3854 /**
3855 * @tc.name: FaultLoggerdSystemTest056
3856 * @tc.desc: test CPP DumpCatch API: PID(apppid), TID(0)
3857 * @tc.type: FUNC
3858 */
3859 HWTEST_F (FaultLoggerdSystemTest, FaultLoggerdSystemTest056, TestSize.Level2)
3860 {
3861 GTEST_LOG_(INFO) << "FaultLoggerdSystemTest056: start uid:" << getuid();
3862 FaultLoggerdSystemTest::StartCrasherLoop(4);
3863 DfxDumpCatcher dumplog;
3864 std::string msg = "";
3865 bool ret = dumplog.DumpCatch(FaultLoggerdSystemTest::loopAppPid, 0, msg);
3866 GTEST_LOG_(INFO) << ret;
3867 GTEST_LOG_(INFO) << msg;
3868 int count = 0;
3869 string log[] = {"Tid:", "#00", "/data/crasher_cpp", "Name:SubTestThread", "usleep"};
3870 log[0] = log[0] +std::to_string(FaultLoggerdSystemTest::loopAppPid);
3871 string::size_type idx;
3872 int j = 0;
3873 for (int x = 0; x < 5; x = x + 1) {
3874 idx = msg.find(log[j]);
3875 if (idx != string::npos) {
3876 GTEST_LOG_(INFO) << log[j];
3877 count++;
3878 }
3879 j++;
3880 }
3881 EXPECT_EQ(count, 5) << "FaultLoggerdSystemTest056 Failed";
3882 FaultLoggerdSystemTest::KillCrasherLoopForSomeCase(3);
3883 GTEST_LOG_(INFO) << "FaultLoggerdSystemTest056: end.";
3884 }
3885
3886 /**
3887 * @tc.name: FaultLoggerdSystemTest057
3888 * @tc.desc: test dumpcatcher command: -p rootpid
3889 * @tc.type: FUNC
3890 */
3891 HWTEST_F (FaultLoggerdSystemTest, FaultLoggerdSystemTest057, TestSize.Level2)
3892 {
3893 GTEST_LOG_(INFO) << "FaultLoggerdSystemTest057: start uid:" << getuid();
3894 FaultLoggerdSystemTest::StartCrasherLoop(4);
3895 std::string procCMD = "dumpcatcher -p " + std::to_string(FaultLoggerdSystemTest::loopAppPid);
3896 string procDumpLog = FaultLoggerdSystemTest::ProcessDumpCommands(procCMD);
3897 GTEST_LOG_(INFO) << "procDumpLog: " << procDumpLog;
3898 int count = 0;
3899 string log[] = {"", "Name:crasher", "Name:SubTestThread", "#00", "/data/crasher"};
3900 log[0] = log[0] + std::to_string(FaultLoggerdSystemTest::loopAppPid);
3901 string::size_type idx;
3902 for (int i = 0; i < 5; i++) {
3903 idx = procDumpLog.find(log[i]);
3904 if (idx != string::npos) {
3905 GTEST_LOG_(INFO) << log[i];
3906 count++;
3907 }
3908 }
3909 EXPECT_EQ(count, 5) << "FaultLoggerdSystemTest057 Failed";
3910 FaultLoggerdSystemTest::KillCrasherLoopForSomeCase(3);
3911 GTEST_LOG_(INFO) << "FaultLoggerdSystemTest057: end.";
3912 }
3913
3914 /**
3915 * @tc.name: FaultLoggerdSystemTest058
3916 * @tc.desc: test C crasher application: STACKOF
3917 * @tc.type: FUNC
3918 */
3919 HWTEST_F (FaultLoggerdSystemTest, FaultLoggerdSystemTest058, TestSize.Level2)
3920 {
3921 GTEST_LOG_(INFO) << "FaultLoggerdSystemTest058: start.";
3922 std::string cmd = "STACKOF";
3923 int cTest = 0;
3924 std::string filePathPid = FaultLoggerdSystemTest::GetfileNamePrefix(cmd, cTest);
3925 if (filePathPid.size() < NUMBER_TEN) {
3926 EXPECT_EQ(true, false) << "ProcessDfxRequestTest058 Failed";
3927 } else {
3928 GTEST_LOG_(INFO) << "current filePath and pid = \n" << filePathPid;
3929 char filePath[ARRAY_SIZE_HUNDRED];
3930 char pid[ARRAY_SIZE_HUNDRED];
3931 int res = sscanf_s(filePathPid.c_str(), "%s %s", filePath, sizeof(filePath) - 1, pid, sizeof(pid) - 1);
3932 if (res <= 0) {
3933 GTEST_LOG_(INFO) << "sscanf_s failed.";
3934 }
3935 GTEST_LOG_(INFO) << "current filepath: \n" << filePath;
3936 GTEST_LOG_(INFO) << "current pid: \n" << pid;
3937 std::string filePathStr = filePath;
3938 std::string pidStr = pid;
3939 int ret = FaultLoggerdSystemTest::CheckCountNum(filePathStr, pidStr, cmd);
3940 GTEST_LOG_(INFO) << "current ret value: \n" << ret;
3941 EXPECT_EQ(ret, 0) << "ProcessDfxRequestTest058 Failed";
3942 GTEST_LOG_(INFO) << "FaultLoggerdSystemTest058: end.";
3943 }
3944 }
3945
3946 /**
3947 * @tc.name: FaultLoggerdSystemTest059
3948 * @tc.desc: test CPP crasher application: STACKOF
3949 * @tc.type: FUNC
3950 */
3951 HWTEST_F (FaultLoggerdSystemTest, FaultLoggerdSystemTest059, TestSize.Level2)
3952 {
3953 GTEST_LOG_(INFO) << "FaultLoggerdSystemTest059: start.";
3954 std::string cmd = "STACKOF";
3955 int cppTest = 1;
3956 std::string filePathPid = FaultLoggerdSystemTest::GetfileNamePrefix(cmd, cppTest);
3957 if (filePathPid.size() < NUMBER_TEN) {
3958 EXPECT_EQ(true, false) << "ProcessDfxRequestTest059 Failed";
3959 } else {
3960 GTEST_LOG_(INFO) << "current filePath and pid = \n" << filePathPid;
3961 char filePath[ARRAY_SIZE_HUNDRED];
3962 char pid[ARRAY_SIZE_HUNDRED];
3963 int res = sscanf_s(filePathPid.c_str(), "%s %s", filePath, sizeof(filePath) - 1, pid, sizeof(pid) - 1);
3964 if (res <= 0) {
3965 GTEST_LOG_(INFO) << "sscanf_s failed.";
3966 }
3967 GTEST_LOG_(INFO) << "current filepath: \n" << filePath;
3968 GTEST_LOG_(INFO) << "current pid: \n" << pid;
3969 std::string filePathStr = filePath;
3970 std::string pidStr = pid;
3971 int ret = FaultLoggerdSystemTest::CheckCountNum(filePathStr, pidStr, cmd);
3972 GTEST_LOG_(INFO) << "current ret value: \n" << ret;
3973 EXPECT_EQ(ret, 0) << "ProcessDfxRequestTest059 Failed";
3974 GTEST_LOG_(INFO) << "FaultLoggerdSystemTest059: end.";
3975 }
3976 }
3977 /**
3978 * @tc.name: FaultLoggerdSystemTest024
3979 * @tc.desc: test CPP crasher application: OOM
3980 * @tc.type: FUNC
3981 */
3982 HWTEST_F (FaultLoggerdSystemTest, FaultLoggerdSystemTest024, TestSize.Level2)
3983 {
3984 GTEST_LOG_(INFO) << "FaultLoggerdSystemTest024: start.";
3985 std::string cmd = "OOM";
3986 int cppTest = 1;
3987 std::string filePathPid = FaultLoggerdSystemTest::GetfileNamePrefix(cmd, cppTest);
3988
3989 GTEST_LOG_(INFO) << "current filePath and pid = \n" << filePathPid;
3990 if (filePathPid.size() < NUMBER_TEN) {
3991 EXPECT_EQ(true, false) << "FaultLoggerdSystemTest024 Failed";
3992 } else {
3993 char filePath[ARRAY_SIZE_HUNDRED] = { 0, };
3994 char pid[ARRAY_SIZE_HUNDRED] = { 0, };
3995 int res = sscanf_s(filePathPid.c_str(), "%s %s", filePath, sizeof(filePath) - 1, pid, sizeof(pid) - 1);
3996 if (res <= 0) {
3997 GTEST_LOG_(INFO) << "sscanf_s failed.";
3998 }
3999 GTEST_LOG_(INFO) << "current filepath: \n" << filePath;
4000 GTEST_LOG_(INFO) << "current pid: \n" << pid;
4001 std::string filePathStr = filePath;
4002 std::string pidStr = pid;
4003 int ret = FaultLoggerdSystemTest::CheckCountNum(filePathStr, pidStr, cmd);
4004 GTEST_LOG_(INFO) << "current ret value: \n" << ret;
4005 EXPECT_EQ(ret, 1) << "ProcessDfxRequestTest024 Failed";
4006 GTEST_LOG_(INFO) << "ProcessDfxRequestTest024: end.";
4007 }
4008 }
4009
4010 /**
4011 * @tc.name: FaultLoggerdSystemTest012
4012 * @tc.desc: test C crasher application: OOM
4013 * @tc.type: FUNC
4014 */
4015 HWTEST_F (FaultLoggerdSystemTest, FaultLoggerdSystemTest012, TestSize.Level2)
4016 {
4017 GTEST_LOG_(INFO) << "FaultLoggerdSystemTest012: start.";
4018 std::string cmd = "OOM";
4019 int cTest = 0;
4020 std::string filePathPid = FaultLoggerdSystemTest::GetfileNamePrefix(cmd, cTest);
4021
4022 GTEST_LOG_(INFO) << "current filePath and pid = \n" << filePathPid;
4023 if (filePathPid.size() < NUMBER_TEN) {
4024 EXPECT_EQ(true, false) << "FaultLoggerdSystemTest012 Failed";
4025 } else {
4026 char filePath[ARRAY_SIZE_HUNDRED] = { 0, };
4027 char pid[ARRAY_SIZE_HUNDRED] = { 0, };
4028 int res = sscanf_s(filePathPid.c_str(), "%s %s", filePath, sizeof(filePath) - 1, pid, sizeof(pid) - 1);
4029 if (res <= 0) {
4030 GTEST_LOG_(INFO) << "sscanf_s failed.";
4031 }
4032 GTEST_LOG_(INFO) << "current filepath: \n" << filePath;
4033 GTEST_LOG_(INFO) << "current pid: \n" << pid;
4034 std::string filePathStr = filePath;
4035 std::string pidStr = pid;
4036 int ret = FaultLoggerdSystemTest::CheckCountNum(filePathStr, pidStr, cmd);
4037 GTEST_LOG_(INFO) << "current ret value: \n" << ret;
4038 EXPECT_EQ(ret, 1) << "FaultLoggerdSystemTest012 Failed";
4039 GTEST_LOG_(INFO) << "FaultLoggerdSystemTest012: end.";
4040 }
4041 }
4042 /**
4043 * @tc.name: FaultLoggerdSystemTest0110
4044 * @tc.desc: test CPP crasher application: PCZero
4045 * @tc.type: FUNC
4046 */
4047 HWTEST_F (FaultLoggerdSystemTest, FaultLoggerdSystemTest0110, TestSize.Level2)
4048 {
4049 GTEST_LOG_(INFO) << "FaultLoggerdSystemTest0110: start.";
4050 std::string cmd = "PCZero";
4051 int cppTest = 1;
4052 std::string filePathPid = FaultLoggerdSystemTest::GetfileNamePrefix(cmd, cppTest);
4053
4054 GTEST_LOG_(INFO) << "current filePath and pid = \n" << filePathPid;
4055 if (filePathPid.size() < NUMBER_TEN) {
4056 EXPECT_EQ(true, false) << "FaultLoggerdSystemTest0110 Failed";
4057 } else {
4058 char filePath[ARRAY_SIZE_HUNDRED] = { 0, };
4059 char pid[ARRAY_SIZE_HUNDRED] = { 0, };
4060 int res = sscanf_s(filePathPid.c_str(), "%s %s", filePath, sizeof(filePath) - 1, pid, sizeof(pid) - 1);
4061 if (res <= 0) {
4062 GTEST_LOG_(INFO) << "sscanf_s failed.";
4063 }
4064 GTEST_LOG_(INFO) << "current filepath: \n" << filePath;
4065 GTEST_LOG_(INFO) << "current pid: \n" << pid;
4066 std::string filePathStr = filePath;
4067 std::string pidStr = pid;
4068 int ret = FaultLoggerdSystemTest::CheckCountNumPCZero(filePathStr, pidStr);
4069 GTEST_LOG_(INFO) << "current ret value: \n" << ret;
4070 EXPECT_EQ(ret, 0) << "FaultLoggerdSystemTest0110 Failed";
4071 GTEST_LOG_(INFO) << "FaultLoggerdSystemTest0110: end.";
4072 }
4073 }
4074
4075 /**
4076 * @tc.name: FaultLoggerdSystemTest0111
4077 * @tc.desc: test C crasher application: PCZero
4078 * @tc.type: FUNC
4079 */
4080 HWTEST_F (FaultLoggerdSystemTest, FaultLoggerdSystemTest0111, TestSize.Level2)
4081 {
4082 GTEST_LOG_(INFO) << "FaultLoggerdSystemTest0111: start.";
4083 std::string cmd = "PCZero";
4084 int cTest = 0;
4085 std::string filePathPid = FaultLoggerdSystemTest::GetfileNamePrefix(cmd, cTest);
4086
4087 GTEST_LOG_(INFO) << "current filePath and pid = \n" << filePathPid;
4088 if (filePathPid.size() < NUMBER_TEN) {
4089 EXPECT_EQ(true, false) << "FaultLoggerdSystemTest0111 Failed";
4090 } else {
4091 char filePath[ARRAY_SIZE_HUNDRED] = { 0, };
4092 char pid[ARRAY_SIZE_HUNDRED] = { 0, };
4093 int res = sscanf_s(filePathPid.c_str(), "%s %s", filePath, sizeof(filePath) - 1, pid, sizeof(pid) - 1);
4094 if (res <= 0) {
4095 GTEST_LOG_(INFO) << "sscanf_s failed.";
4096 }
4097 GTEST_LOG_(INFO) << "current filepath: \n" << filePath;
4098 GTEST_LOG_(INFO) << "current pid: \n" << pid;
4099 std::string filePathStr = filePath;
4100 std::string pidStr = pid;
4101 int ret = FaultLoggerdSystemTest::CheckCountNumPCZero(filePathStr, pidStr);
4102 GTEST_LOG_(INFO) << "current ret value: \n" << ret;
4103 EXPECT_EQ(ret, 0) << "FaultLoggerdSystemTest0111 Failed";
4104 GTEST_LOG_(INFO) << "FaultLoggerdSystemTest0111: end.";
4105 }
4106 }
4107
4108 /**
4109 * @tc.name: FaultLoggerdSystemTest0112
4110 * @tc.desc: test C crasher application: MTCrash
4111 * @tc.type: FUNC
4112 */
4113 HWTEST_F (FaultLoggerdSystemTest, FaultLoggerdSystemTest0112, TestSize.Level2)
4114 {
4115 GTEST_LOG_(INFO) << "FaultLoggerdSystemTest0112: start.";
4116 std::string cmd = "MTCrash";
4117 int cTest = 0;
4118 std::string filePathPid = FaultLoggerdSystemTest::GetfileNamePrefix(cmd, cTest);
4119
4120 GTEST_LOG_(INFO) << "current filePath and pid = \n" << filePathPid;
4121 if (filePathPid.size() < NUMBER_TEN) {
4122 EXPECT_EQ(true, false) << "FaultLoggerdSystemTest0112 Failed";
4123 } else {
4124 char filePath[ARRAY_SIZE_HUNDRED] = { 0, };
4125 char pid[ARRAY_SIZE_HUNDRED] = { 0, };
4126 int res = sscanf_s(filePathPid.c_str(), "%s %s", filePath, sizeof(filePath) - 1, pid, sizeof(pid) - 1);
4127 if (res <= 0) {
4128 GTEST_LOG_(INFO) << "sscanf_s failed.";
4129 }
4130 GTEST_LOG_(INFO) << "current filepath: \n" << filePath;
4131 GTEST_LOG_(INFO) << "current pid: \n" << pid;
4132 std::string filePathStr = filePath;
4133 std::string pidStr = pid;
4134 int ret = FaultLoggerdSystemTest::CheckCountNumMultiThread(filePathStr, pidStr);
4135 GTEST_LOG_(INFO) << "current ret value: \n" << ret;
4136 EXPECT_EQ(ret, 0) << "FaultLoggerdSystemTest0112 Failed";
4137 GTEST_LOG_(INFO) << "FaultLoggerdSystemTest0112: end.";
4138 }
4139 }
4140
4141 /**
4142 * @tc.name: FaultLoggerdSystemTest0113
4143 * @tc.desc: test CPP crasher application: MTCrash
4144 * @tc.type: FUNC
4145 */
4146 HWTEST_F (FaultLoggerdSystemTest, FaultLoggerdSystemTest0113, TestSize.Level2)
4147 {
4148 GTEST_LOG_(INFO) << "FaultLoggerdSystemTest0113: start.";
4149 std::string cmd = "MTCrash";
4150 int cppTest = 1;
4151 std::string filePathPid = FaultLoggerdSystemTest::GetfileNamePrefix(cmd, cppTest);
4152
4153 GTEST_LOG_(INFO) << "current filePath and pid = \n" << filePathPid;
4154 if (filePathPid.size() < NUMBER_TEN) {
4155 EXPECT_EQ(true, false) << "FaultLoggerdSystemTest0113 Failed";
4156 } else {
4157 char filePath[ARRAY_SIZE_HUNDRED] = { 0, };
4158 char pid[ARRAY_SIZE_HUNDRED] = { 0, };
4159 int res = sscanf_s(filePathPid.c_str(), "%s %s", filePath, sizeof(filePath) - 1, pid, sizeof(pid) - 1);
4160 if (res <= 0) {
4161 GTEST_LOG_(INFO) << "sscanf_s failed.";
4162 }
4163 GTEST_LOG_(INFO) << "current filepath: \n" << filePath;
4164 GTEST_LOG_(INFO) << "current pid: \n" << pid;
4165 std::string filePathStr = filePath;
4166 std::string pidStr = pid;
4167 int ret = FaultLoggerdSystemTest::CheckCountNumMultiThread(filePathStr, pidStr);
4168 GTEST_LOG_(INFO) << "current ret value: \n" << ret;
4169 EXPECT_EQ(ret, 0) << "FaultLoggerdSystemTest0113 Failed";
4170 GTEST_LOG_(INFO) << "FaultLoggerdSystemTest0113: end.";
4171 }
4172 }
4173
4174 /**
4175 * @tc.name: FaultLoggerdSystemTest0118
4176 * @tc.desc: test CPP crasher application: StackOver64
4177 * @tc.type: FUNC
4178 */
4179 HWTEST_F (FaultLoggerdSystemTest, FaultLoggerdSystemTest0118, TestSize.Level2)
4180 {
4181 GTEST_LOG_(INFO) << "FaultLoggerdSystemTest0118: start.";
4182 std::string cmd = "StackOver64";
4183 int cppTest = 1;
4184 std::string filePathPid = FaultLoggerdSystemTest::GetfileNamePrefix(cmd, cppTest);
4185
4186 GTEST_LOG_(INFO) << "current filePath and pid = \n" << filePathPid;
4187 if (filePathPid.size() < NUMBER_TEN) {
4188 EXPECT_EQ(true, false) << "FaultLoggerdSystemTest0118 Failed";
4189 } else {
4190 char filePath[ARRAY_SIZE_HUNDRED] = { 0, };
4191 char pid[ARRAY_SIZE_HUNDRED] = { 0, };
4192 int res = sscanf_s(filePathPid.c_str(), "%s %s", filePath, sizeof(filePath) - 1, pid, sizeof(pid) - 1);
4193 if (res <= 0) {
4194 GTEST_LOG_(INFO) << "sscanf_s failed.";
4195 }
4196 GTEST_LOG_(INFO) << "current filepath: \n" << filePath;
4197 GTEST_LOG_(INFO) << "current pid: \n" << pid;
4198 std::string filePathStr = filePath;
4199 std::string pidStr = pid;
4200 int ret = FaultLoggerdSystemTest::CheckCountNumOverStack(filePathStr, pidStr);
4201 GTEST_LOG_(INFO) << "current ret value: \n" << ret;
4202 EXPECT_EQ(ret, 0) << "FaultLoggerdSystemTest0118 Failed";
4203 GTEST_LOG_(INFO) << "FaultLoggerdSystemTest0118: end.";
4204 }
4205 }
4206
4207 /**
4208 * @tc.name: FaultLoggerdSystemTest0119
4209 * @tc.desc: test C crasher application: StackOver64
4210 * @tc.type: FUNC
4211 */
4212 HWTEST_F (FaultLoggerdSystemTest, FaultLoggerdSystemTest0119, TestSize.Level2)
4213 {
4214 GTEST_LOG_(INFO) << "FaultLoggerdSystemTest0119: start.";
4215 std::string cmd = "StackOver64";
4216 int cTest = 0;
4217 std::string filePathPid = FaultLoggerdSystemTest::GetfileNamePrefix(cmd, cTest);
4218
4219 GTEST_LOG_(INFO) << "current filePath and pid = \n" << filePathPid;
4220 if (filePathPid.size() < NUMBER_TEN) {
4221 EXPECT_EQ(true, false) << "FaultLoggerdSystemTest0119 Failed";
4222 } else {
4223 char filePath[ARRAY_SIZE_HUNDRED] = { 0, };
4224 char pid[ARRAY_SIZE_HUNDRED] = { 0, };
4225 int res = sscanf_s(filePathPid.c_str(), "%s %s", filePath, sizeof(filePath) - 1, pid, sizeof(pid) - 1);
4226 if (res <= 0) {
4227 GTEST_LOG_(INFO) << "sscanf_s failed.";
4228 }
4229 GTEST_LOG_(INFO) << "current filepath: \n" << filePath;
4230 GTEST_LOG_(INFO) << "current pid: \n" << pid;
4231 std::string filePathStr = filePath;
4232 std::string pidStr = pid;
4233 int ret = FaultLoggerdSystemTest::CheckCountNumOverStack(filePathStr, pidStr);
4234 GTEST_LOG_(INFO) << "current ret value: \n" << ret;
4235 EXPECT_EQ(ret, 0) << "FaultLoggerdSystemTest0119 Failed";
4236 GTEST_LOG_(INFO) << "FaultLoggerdSystemTest0119: end.";
4237 }
4238 }
4239
4240 /**
4241 * @tc.name: FaultLoggerdSystemTest0120
4242 * @tc.desc: test DumpCatch API: app unsigned PID(systempid), unsigned TID(systempid)
4243 * @tc.type: FUNC
4244 */
4245 HWTEST_F (FaultLoggerdSystemTest, FaultLoggerdSystemTest0120, TestSize.Level2)
4246 {
4247 GTEST_LOG_(INFO) << "FaultLoggerdSystemTest0120: start.";
4248 FaultLoggerdSystemTest::StartCrasherLoopForUnsingPidAndTid(0);
4249 DfxDumpCatcher dumplog;
4250 std::string msg = "";
4251 bool ret = dumplog.DumpCatch(FaultLoggerdSystemTest::unsigLoopSysPid, FaultLoggerdSystemTest::unsigLoopSysPid, msg);
4252 GTEST_LOG_(INFO) << ret;
4253 GTEST_LOG_(INFO) << msg;
4254 int count = 0;
4255 string log[] = {"Tid:", "Name:crasher", "#00", "/data/crasher"};
4256 log[0] = log[0] +std::to_string(FaultLoggerdSystemTest::unsigLoopSysPid);
4257 string::size_type idx;
4258 int j = 0;
4259 for (int x = 0; x < 4; x = x + 1) {
4260 idx = msg.find(log[j]);
4261 if (idx != string::npos) {
4262 count++;
4263 }
4264 j++;
4265 }
4266 GTEST_LOG_(INFO) << count;
4267 EXPECT_EQ(count, 4) << "FaultLoggerdSystemTest0120 Failed";
4268 FaultLoggerdSystemTest::KillCrasherLoopForSomeCase(4);
4269 GTEST_LOG_(INFO) << "FaultLoggerdSystemTest0120: end.";
4270 }
4271
4272 /**
4273 * @tc.name: FaultLoggerdSystemTest0121
4274 * @tc.desc: test DumpCatch API: app unsigned PID(systempid), unsigned TID(systempid)
4275 * @tc.type: FUNC
4276 */
4277 HWTEST_F (FaultLoggerdSystemTest, FaultLoggerdSystemTest0121, TestSize.Level2)
4278 {
4279 GTEST_LOG_(INFO) << "FaultLoggerdSystemTest0121: start.";
4280 FaultLoggerdSystemTest::StartCrasherLoopForUnsingPidAndTid(1);
4281 DfxDumpCatcher dumplog;
4282 std::string msg = "";
4283 bool ret = dumplog.DumpCatch(FaultLoggerdSystemTest::unsigLoopSysPid, FaultLoggerdSystemTest::unsigLoopSysPid, msg);
4284 GTEST_LOG_(INFO) << ret;
4285 GTEST_LOG_(INFO) << msg;
4286 int count = 0;
4287 string log[] = {"Tid:", "Name:crasher", "#00", "/data/crasher"};
4288 log[0] = log[0] +std::to_string(FaultLoggerdSystemTest::unsigLoopSysPid);
4289 string::size_type idx;
4290 int j = 0;
4291 for (int x = 0; x < 4; x = x + 1) {
4292 idx = msg.find(log[j]);
4293 if (idx != string::npos) {
4294 count++;
4295 }
4296 j++;
4297 }
4298 GTEST_LOG_(INFO) << count;
4299 EXPECT_EQ(count, 4) << "FaultLoggerdSystemTest0121 Failed";
4300 FaultLoggerdSystemTest::KillCrasherLoopForSomeCase(4);
4301 GTEST_LOG_(INFO) << "FaultLoggerdSystemTest0121: end.";
4302 }
4303
CrashInChildThread()4304 static void CrashInChildThread()
4305 {
4306 printf("CrashInChildThread(): TID = %ld\n", (long) gettid());
4307 raise(SIGSEGV);
4308 }
4309
RunInNewPidNs(void * arg)4310 static int RunInNewPidNs(void* arg)
4311 {
4312 (void)arg;
4313 printf("RunInNewPidNs(): PID = %ld\n", (long) getpid());
4314 printf("RunInNewPidNs(): TID = %ld\n", (long) gettid());
4315 printf("RunInNewPidNs(): PPID = %ld\n", (long) getppid());
4316 std::thread childThread(CrashInChildThread);
4317 childThread.join();
4318 _exit(0);
4319 }
4320
4321 /**
4322 * @tc.name: FaultLoggerdSystemTest0200
4323 * @tc.desc: test crash in process with pid namespace
4324 * @tc.type: FUNC
4325 */
4326 HWTEST_F (FaultLoggerdSystemTest, FaultLoggerdSystemTest0200, TestSize.Level2)
4327 {
4328 GTEST_LOG_(INFO) << "FaultLoggerdSystemTest0200: start.";
4329 const int stackSz = 1024 * 1024 * 1024; // 1M
4330 void* cloneStack = mmap(NULL, stackSz,
4331 PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS | MAP_STACK, 1, 0);
4332 if (cloneStack == nullptr) {
4333 FAIL();
4334 }
4335 cloneStack = (void *)(((uint8_t *)cloneStack) + stackSz - 1);
4336 int childPid = clone(RunInNewPidNs, cloneStack, CLONE_NEWPID | SIGCHLD, nullptr);
4337 if (childPid <= 0) {
4338 GTEST_LOG_(INFO) << "FaultLoggerdSystemTest0200: Failed to clone new process. errno:" << errno;
4339 }
4340 // wait for log generation
4341 sleep(NUMBER_FOUR);
4342 std::string prefix = "cppcrash-" + std::to_string(childPid);
4343 std::string fileName = GetLogFileName(prefix);
4344 EXPECT_NE(0, fileName.size());
4345 printf("PidNs Crash File:%s\n", fileName.c_str());
4346 string log[] = {
4347 "Pid:", "Uid", "SIGSEGV", "Tid:", "#00",
4348 "Registers:", "FaultStack:", "Maps:"
4349 };
4350 int minRegIdx = 6;
4351 CheckKeywords(fileName, log, sizeof(log) / sizeof(log[0]), minRegIdx);
4352 GTEST_LOG_(INFO) << "FaultLoggerdSystemTest0200: end.";
4353 }
4354 #endif
4355 }
4356