Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Xts Acts
提交
836929f1
X
Xts Acts
项目概览
OpenHarmony
/
Xts Acts
1 年多 前同步成功
通知
9
Star
22
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
X
Xts Acts
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
836929f1
编写于
8月 12, 2021
作者:
O
openharmony_ci
提交者:
Gitee
8月 12, 2021
浏览文件
操作
浏览文件
下载
差异文件
!402 增加faultlogger测试用例
Merge pull request !402 from 土行孙/master
上级
919c3121
ca7ff60f
变更
8
隐藏空白更改
内联
并排
Showing
8 changed file
with
305 addition
and
1 deletion
+305
-1
hiviewdfx/BUILD.gn
hiviewdfx/BUILD.gn
+1
-0
hiviewdfx/faultloggertest/faultloggercpptest/BUILD.gn
hiviewdfx/faultloggertest/faultloggercpptest/BUILD.gn
+41
-0
hiviewdfx/faultloggertest/faultloggercpptest/Test.json
hiviewdfx/faultloggertest/faultloggercpptest/Test.json
+21
-0
hiviewdfx/faultloggertest/faultloggercpptest/faultloggertest.cpp
...fx/faultloggertest/faultloggercpptest/faultloggertest.cpp
+140
-0
hiviewdfx/faultloggertest/faultloggercpptest/genfault.cpp
hiviewdfx/faultloggertest/faultloggercpptest/genfault.cpp
+62
-0
hiviewdfx/faultloggertest/faultloggercpptest/genfault.h
hiviewdfx/faultloggertest/faultloggercpptest/genfault.h
+16
-0
hiviewdfx/utils/native/file_utils.cpp
hiviewdfx/utils/native/file_utils.cpp
+23
-1
hiviewdfx/utils/native/file_utils.h
hiviewdfx/utils/native/file_utils.h
+1
-0
未找到文件。
hiviewdfx/BUILD.gn
浏览文件 @
836929f1
...
...
@@ -15,6 +15,7 @@ group("hiviewdfxtestacts") {
testonly = true
if (is_standard_system) {
deps = [
"faultloggertest/faultloggercpptest:faultloggertest",
"hiappeventtest/hiappeventjstest:hiappeventjstest",
"hilogtest/libhilogtest:libhilogtestacts",
"hisyseventtest/hisyseventcpptest:HiSysEventCPPTest",
...
...
hiviewdfx/faultloggertest/faultloggercpptest/BUILD.gn
0 → 100755
浏览文件 @
836929f1
# Copyright (C) 2021 Huawei Device Co., Ltd.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import("//test/xts/tools/build/suite.gni")
module_output_path = "hits/faultloggertest"
###############################################################################
config("faultloggertest_config") {
visibility = [ ":*" ]
include_dirs = [
"../../utils/native",
"//utils/native/base/include/",
"//base/hiviewdfx/hilog/interfaces/native/innerkits/include",
"genfault.h",
]
}
ohos_moduletest_suite("faultloggertest") {
module_out_path = module_output_path
sources = [
"faultloggertest.cpp",
"genfault.cpp",
]
deps = [
"../../utils/native:utilskit",
"//base/hiviewdfx/hilog/interfaces/native/innerkits:libhilog",
"//third_party/googletest:gtest_main",
"//utils/native/base:utils",
]
configs = [ ":faultloggertest_config" ]
}
hiviewdfx/faultloggertest/faultloggercpptest/Test.json
0 → 100755
浏览文件 @
836929f1
{
"kits"
:
[
{
"push"
:
[
"faultloggertest->/data/local/tmp/faultloggertest"
],
"type"
:
"PushKit"
,
"post-push"
:
[
"chmod -R 777 /data/local/tmp/*"
]
}
],
"driver"
:
{
"native-test-timeout"
:
"120000"
,
"type"
:
"CppTest"
,
"module-name"
:
"faultloggertest"
,
"runtime-hint"
:
"1s"
,
"native-test-device-path"
:
"/data/local/tmp"
},
"description"
:
"Configuration for faultloggertest Tests"
}
\ No newline at end of file
hiviewdfx/faultloggertest/faultloggercpptest/faultloggertest.cpp
0 → 100755
浏览文件 @
836929f1
/*
* Copyright (C) 2021 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <cstdarg>
#include <ctime>
#include <gtest/gtest.h>
#include <pthread.h>
#include "genfault.h"
#include "file_utils.h"
#include "hilog/log_c.h"
#include "hilog/log_cpp.h"
#undef LOG_DOMAIN
#undef LOG_TAG
#define LOG_DOMAIN 0xD003200
#define LOG_TAG "FAULTLOGGERTEST"
using
namespace
OHOS
;
using
namespace
HiviewDFX
;
using
namespace
testing
::
ext
;
using
namespace
std
;
class
faultloggertest
:
public
testing
::
Test
{
public:
static
void
SetUpTestCase
();
static
void
TearDownTestCase
();
void
SetUp
();
void
TearDown
();
pid_t
DoTestProcess
(
int
faulttype
);
int
status
;
private:
};
void
faultloggertest
::
SetUp
()
{
}
void
faultloggertest
::
TearDown
()
{
}
void
faultloggertest
::
SetUpTestCase
()
{
}
void
faultloggertest
::
TearDownTestCase
()
{
}
pid_t
faultloggertest
::
DoTestProcess
(
int
faulttype
)
{
printf
(
"DoTestProcess, param is %d
\r\n
"
,
faulttype
);
pid_t
pid
;
pid
=
fork
();
printf
(
"pid is %d
\r\n
"
,
pid
);
switch
(
pid
)
{
case
-
1
:
std
::
cout
<<
"for pid failed"
<<
std
::
endl
;
break
;
case
0
:
GenFault
(
faulttype
);
break
;
default:
break
;
}
wait
(
&
status
);
printf
(
"sub process end with status %d
\r\n
"
,
status
);
return
pid
;
}
/*
* @tc.name faultlogger Detect a cpp crash happen
* @tc.number DFX_DFR_FaultLogger_0100
* @tc.desc inject a cppcrash fault and check faultlogger can detect the fault
*/
HWTEST_F
(
faultloggertest
,
Faultlogger_Faultdetect
,
Function
|
MediumTest
|
Level1
)
{
pid_t
pid
=
DoTestProcess
(
3
);
printf
(
"pid is %d
\r\n
"
,
pid
);
printf
(
"sub process end with status %d
\r\n
"
,
faultloggertest
::
status
);
ASSERT_FALSE
(
status
==
0
);
std
::
vector
<
std
::
string
>
faultfilelist
;
faultfilelist
=
getfileinpath
(
"/data/log/faultlog/temp/"
);
printf
(
"sizeof faultfilelist is %d
\r\n
"
,
faultfilelist
.
size
());
bool
result
=
false
;
for
(
std
::
string
filename
:
faultfilelist
)
{
printf
(
"file list is %s
\r\n
"
,
filename
.
c_str
());
if
(
filename
.
find
(
"cppcrash-"
+
to_string
(
pid
)))
{
result
=
true
;
}
}
ASSERT_TRUE
(
true
==
result
);
}
/*
* @tc.name faultlogger log file check
* @tc.number DFX_DFR_FaultLogger_0100
* @tc.desc inject a cppcrash fault and check faultlogger file
*/
HWTEST_F
(
faultloggertest
,
Faultlogger_Faultdetect1
,
Function
|
MediumTest
|
Level1
)
{
pid_t
pid
=
DoTestProcess
(
3
);
printf
(
"pid is %d
\r\n
"
,
pid
);
printf
(
"sub process end with status %d
\r\n
"
,
faultloggertest
::
status
);
std
::
vector
<
std
::
string
>
faultfilelist
;
faultfilelist
=
getfileinpath
(
"/data/log/faultlog/temp/"
);
printf
(
"sizeof faultfilelist is %d
\r\n
"
,
faultfilelist
.
size
());
bool
result
=
false
;
std
::
string
faultloggerfile
=
""
;
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
;
break
;
}
}
string
fileinfo
;
fileinfo
=
ReadFile
(
"/data/log/faultlog/temp/"
+
faultloggerfile
);
std
::
vector
<
std
::
string
>
para
=
{
"Pid:"
+
to_string
(
pid
),
"Uid:0"
,
"Process name:./faultloggertest"
,
"Reason:Signal:SIGILL"
,
"Fault thread Info:"
,
"Tid:"
+
to_string
(
pid
),
"Name:faultloggertest"
};
if
(
!
fileinfo
.
empty
())
{
result
=
CheckInfo
(
para
,
fileinfo
);
}
else
{
std
::
cout
<<
"Faultlogger_Faultdetect1 file error"
<<
std
::
endl
;
}
ASSERT_TRUE
(
result
);
GTEST_LOG_
(
INFO
)
<<
"Faultlogger_Faultdetect1 end"
<<
endl
;
}
\ No newline at end of file
hiviewdfx/faultloggertest/faultloggercpptest/genfault.cpp
0 → 100755
浏览文件 @
836929f1
/*
* Copyright (C) 2021 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef TEST_COMMON_H
#define TEST_COMMON_H
#include <stdlib.h>
#include <string.h>
#include <thread>
#include <unistd.h>
typedef
enum
{
FAULT_HEAP
=
1
,
FAULT_STACK
=
2
,
FAULT_NULLPTR
=
3
,
}
FaultType
;
void
FaultHeap
(
int
value
)
{
int
*
arraytest
=
new
int
[
123
];
delete
[]
arraytest
;
printf
(
"%d"
,
arraytest
[
value
]);
}
void
FaultStack
(
int
value
)
{
int
arraytest
[
123
];
printf
(
"value of i is %d"
,
arraytest
[
value
]);
}
void
FaultNullPointer
()
{
const
int
num
=
80
;
int
*
i
=
nullptr
;
*
i
=
num
;
}
void
GenFault
(
int
faulttype
)
{
printf
(
"genFault, param is %d
\r\n
"
,
faulttype
);
switch
(
faulttype
)
{
case
FAULT_HEAP
:
FaultHeap
(
125
);
case
FAULT_STACK
:
FaultStack
(
125
);
case
FAULT_NULLPTR
:
FaultNullPointer
();
break
;
}
}
#endif
\ No newline at end of file
hiviewdfx/faultloggertest/faultloggercpptest/genfault.h
0 → 100755
浏览文件 @
836929f1
/*
* Copyright (C) 2021 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "file_utils.h"
void
GenFault
(
int
faulttype
);
\ No newline at end of file
hiviewdfx/utils/native/file_utils.cpp
浏览文件 @
836929f1
...
...
@@ -202,4 +202,26 @@ std::string ReadFile(std::string filename)
ifile
.
close
();
return
buf
.
str
();
}
#endif
\ No newline at end of file
std
::
vector
<
std
::
string
>
getfileinpath
(
std
::
string
path
)
{
std
::
vector
<
std
::
string
>
filelist
;
DIR
*
dir
;
struct
dirent
*
pdirent
;
dir
=
opendir
(
path
.
c_str
());
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
)
{
continue
;
}
else
{
filelist
.
push_back
(
pdirent
->
d_name
);
}
}
closedir
(
dir
);
}
return
filelist
;
}
#endif
hiviewdfx/utils/native/file_utils.h
浏览文件 @
836929f1
...
...
@@ -41,4 +41,5 @@ std::string ReadFile(std::string filename);
void
CleanCmd
();
std
::
string
ReadOneLine
(
std
::
string
m_path
,
char
*
rBuf
,
int
n
);
void
SaveCmdOutput
(
std
::
string
cmd
,
std
::
string
saveFile
);
std
::
vector
<
std
::
string
>
getfileinpath
(
std
::
string
path
);
#endif
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录