From 5d5fbd425f08b77d52c681dd69b3c61173a40fc9 Mon Sep 17 00:00:00 2001 From: tuxingsun Date: Thu, 12 Aug 2021 09:52:35 +0800 Subject: [PATCH] add faultlogger testcase Signed-off-by: tuxingsun --- .../faultloggercpptest/BUILD.gn | 10 ++--- .../faultloggercpptest/faultloggertest.cpp | 6 +-- .../faultloggercpptest/genfault.cpp | 38 ++++++++----------- .../faultloggercpptest/genfault.h | 2 +- hiviewdfx/utils/native/file_utils.cpp | 10 ++--- 5 files changed, 29 insertions(+), 37 deletions(-) diff --git a/hiviewdfx/faultloggertest/faultloggercpptest/BUILD.gn b/hiviewdfx/faultloggertest/faultloggercpptest/BUILD.gn index 5934c9041..4276b9c15 100755 --- a/hiviewdfx/faultloggertest/faultloggercpptest/BUILD.gn +++ b/hiviewdfx/faultloggertest/faultloggercpptest/BUILD.gn @@ -21,15 +21,15 @@ config("faultloggertest_config") { "../../utils/native", "//utils/native/base/include/", "//base/hiviewdfx/hilog/interfaces/native/innerkits/include", - "genfault.h" + "genfault.h", ] } ohos_moduletest_suite("faultloggertest") { module_out_path = module_output_path - sources = [ - "faultloggertest.cpp", - "genfault.cpp" - ] + sources = [ + "faultloggertest.cpp", + "genfault.cpp", + ] deps = [ "../../utils/native:utilskit", "//base/hiviewdfx/hilog/interfaces/native/innerkits:libhilog", diff --git a/hiviewdfx/faultloggertest/faultloggercpptest/faultloggertest.cpp b/hiviewdfx/faultloggertest/faultloggercpptest/faultloggertest.cpp index 9d81e84de..13467c3e0 100755 --- a/hiviewdfx/faultloggertest/faultloggercpptest/faultloggertest.cpp +++ b/hiviewdfx/faultloggertest/faultloggercpptest/faultloggertest.cpp @@ -67,7 +67,7 @@ pid_t faultloggertest::DoTestProcess(int faulttype) std::cout<<"for pid failed"< typedef enum { - FAULT_DIVZERO = 0, - FAULT_HEAP_OVERFLOW = 1, - FAULT_STACK_OVERFLOW = 2, - FAULT_NULL_POINTER = 3, + FAULT_HEAP = 1, + FAULT_STACK = 2, + FAULT_NULLPTR = 3, }FaultType; -void faultdividezero(int value) -{ - printf("faultdividezero, param is %d\r\n", value); - printf("faultdividezero result = %d\r\n", 123 / value); -} - -void faultheapoverflow(int value) +void FaultHeap(int value) { int* arraytest = new int[123]; @@ -40,30 +33,29 @@ void faultheapoverflow(int value) printf("%d", arraytest[value]); } -void faultstackoverflow(int value) +void FaultStack(int value) { int arraytest[123]; printf("value of i is %d", arraytest[value]); } -void faultnullpointer() + +void FaultNullPointer() { const int num = 80; - int *i = NULL; + int *i = nullptr; *i = num; } -void genFault(int faulttype) +void GenFault(int faulttype) { printf("genFault, param is %d\r\n", faulttype); switch (faulttype) { - case FAULT_DIVZERO: - faultdividezero(0); - case FAULT_HEAP_OVERFLOW: - faultheapoverflow(125); - case FAULT_STACK_OVERFLOW: - faultstackoverflow(125); - case FAULT_NULL_POINTER: - faultnullpointer(); + case FAULT_HEAP: + FaultHeap(125); + case FAULT_STACK: + FaultStack(125); + case FAULT_NULLPTR: + FaultNullPointer(); break; } } diff --git a/hiviewdfx/faultloggertest/faultloggercpptest/genfault.h b/hiviewdfx/faultloggertest/faultloggercpptest/genfault.h index f72e7774d..7dc209d33 100755 --- a/hiviewdfx/faultloggertest/faultloggercpptest/genfault.h +++ b/hiviewdfx/faultloggertest/faultloggercpptest/genfault.h @@ -13,4 +13,4 @@ * limitations under the License. */ #include "file_utils.h" -void genFault(int faulttype); \ No newline at end of file +void GenFault(int faulttype); \ No newline at end of file diff --git a/hiviewdfx/utils/native/file_utils.cpp b/hiviewdfx/utils/native/file_utils.cpp index 4469ced62..05b8feba5 100755 --- a/hiviewdfx/utils/native/file_utils.cpp +++ b/hiviewdfx/utils/native/file_utils.cpp @@ -209,12 +209,12 @@ std::vector getfileinpath(std::string path) DIR *dir; struct dirent *pdirent; dir = opendir(path.c_str()); - if (dir != NULL) { - while((pdirent = readdir(dir)) != NULL) { - if(strncmp(pdirent->d_name, ".", strlen(pdirent->d_name)) == 0 || - strncmp(pdirent->d_name, "..", strlen(pdirent->d_name)) == 0) { + if (dir != nullptr) { + while ((pdirent = readdir(dir)) != nullptr) { + if (strncmp(pdirent->d_name, ".", strlen(pdirent->d_name)) == 0 || + strncmp(pdirent->d_name, "..", strlen(pdirent->d_name)) == 0) { continue; - } else if(pdirent->d_type == 4) { + } else if (pdirent->d_type == 4) { continue; } else { filelist.push_back(pdirent->d_name); -- GitLab