提交 5d5fbd42 编写于 作者: T tuxingsun

add faultlogger testcase

Signed-off-by: Ntuxingsun <duanhaizhen@huawei.com>
上级 61a656a8
......@@ -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",
......
......@@ -67,7 +67,7 @@ pid_t faultloggertest::DoTestProcess(int faulttype)
std::cout<<"for pid failed"<<std::endl;
break;
case 0:
genFault(faulttype);
GenFault(faulttype);
break;
default:
break;
......@@ -93,7 +93,7 @@ HWTEST_F(faultloggertest, Faultlogger_Faultdetect, Function|MediumTest|Level1)
faultfilelist = getfileinpath("/data/log/faultlog/temp/");
printf("sizeof faultfilelist is %d\r\n", faultfilelist.size());
bool result = false;
for(std::string filename : faultfilelist) {
for (std::string filename : faultfilelist) {
printf("file list is %s\r\n", filename.c_str());
if (filename.find("cppcrash-" + to_string(pid))) {
result = true;
......@@ -117,7 +117,7 @@ HWTEST_F(faultloggertest, Faultlogger_Faultdetect1, Function|MediumTest|Level1)
printf("sizeof faultfilelist is %d\r\n", faultfilelist.size());
bool result = false;
std::string faultloggerfile = "";
for(std::string filename : faultfilelist) {
for (std::string filename : faultfilelist) {
if (filename.find("cppcrash-" + to_string(pid)) != std::string::npos) {
printf("file list is %s\r\n", filename.c_str());
faultloggerfile = filename;
......
......@@ -20,19 +20,12 @@
#include <unistd.h>
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;
}
}
......
......@@ -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
......@@ -209,12 +209,12 @@ std::vector<std::string> 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);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册