Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Xts Acts
提交
ca556c4d
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看板
提交
ca556c4d
编写于
6月 23, 2022
作者:
C
chenxuihui
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
hiappevent bugfix
Signed-off-by:
N
chenxuihui
<
chenxuhui2@huawei.com
>
上级
c3f23eeb
变更
5
显示空白变更内容
内联
并排
Showing
5 changed file
with
304 addition
and
0 deletion
+304
-0
hiviewdfx/hiappeventtest/hiappeventcpptest/BUILD.gn
hiviewdfx/hiappeventtest/hiappeventcpptest/BUILD.gn
+2
-0
hiviewdfx/hiappeventtest/hiappeventcpptest/HiAppEventCPPTest.cpp
...fx/hiappeventtest/hiappeventcpptest/HiAppEventCPPTest.cpp
+1
-0
hiviewdfx/utils/native/BUILD.gn
hiviewdfx/utils/native/BUILD.gn
+38
-0
hiviewdfx/utils/native/file_utils.cpp
hiviewdfx/utils/native/file_utils.cpp
+218
-0
hiviewdfx/utils/native/file_utils.h
hiviewdfx/utils/native/file_utils.h
+45
-0
未找到文件。
hiviewdfx/hiappeventtest/hiappeventcpptest/BUILD.gn
浏览文件 @
ca556c4d
...
@@ -20,6 +20,7 @@ config("hilogtest_config") {
...
@@ -20,6 +20,7 @@ config("hilogtest_config") {
visibility = [ ":*" ]
visibility = [ ":*" ]
include_dirs = [
include_dirs = [
"//utils/native/base/include/",
"//utils/native/base/include/",
"../../utils/native",
"//base/hiviewdfx/hilog/interfaces/native/innerkits/include",
"//base/hiviewdfx/hilog/interfaces/native/innerkits/include",
"//base/hiviewdfx/hiappevent/interfaces/native/kits/include/hiappevent",
"//base/hiviewdfx/hiappevent/interfaces/native/kits/include/hiappevent",
"//base/hiviewdfx/hiappevent/frameworks/native/libhiappevent/include",
"//base/hiviewdfx/hiappevent/frameworks/native/libhiappevent/include",
...
@@ -34,6 +35,7 @@ ohos_moduletest_suite("HiAppEventCPPTest") {
...
@@ -34,6 +35,7 @@ ohos_moduletest_suite("HiAppEventCPPTest") {
"//base/hiviewdfx/hilog/interfaces/native/innerkits:libhilog",
"//base/hiviewdfx/hilog/interfaces/native/innerkits:libhilog",
"//third_party/googletest:gtest_main",
"//third_party/googletest:gtest_main",
"//utils/native/base:utils",
"//utils/native/base:utils",
"../../utils/native:utilskit",
]
]
configs = [ ":hilogtest_config" ]
configs = [ ":hilogtest_config" ]
}
}
hiviewdfx/hiappeventtest/hiappeventcpptest/HiAppEventCPPTest.cpp
浏览文件 @
ca556c4d
...
@@ -24,6 +24,7 @@
...
@@ -24,6 +24,7 @@
#include "hiappevent.h"
#include "hiappevent.h"
#include "hiappevent_config.h"
#include "hiappevent_config.h"
#include "hilog/log.h"
#include "hilog/log.h"
#include "file_utils.h"
using
namespace
std
;
using
namespace
std
;
...
...
hiviewdfx/utils/native/BUILD.gn
0 → 100755
浏览文件 @
ca556c4d
# Copyright (C) 2021-2022 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("//build/ohos.gni")
import("//test/xts/tools/build/suite.gni")
###############################################################################
config("utils_config") {
visibility = [ ":*" ]
include_dirs = [
"//third_party/cJSON/",
"//third_party/zlib/",
"//utils/native/base/",
]
}
sources_common = [ "file_utils.cpp" ]
ohos_static_library("utilskit") {
sources = sources_common
configs = [ ":utils_config" ]
#external_deps = [ "hilog:libhilog" ]
deps = [
"//base/hiviewdfx/hilog/interfaces/native/innerkits:libhilog",
"//base/hiviewdfx/hiview/base:hiviewbase",
"//utils/native/base:utils",
]
}
hiviewdfx/utils/native/file_utils.cpp
0 → 100755
浏览文件 @
ca556c4d
/*
* Copyright (C) 2021-2022 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 "file_utils.h"
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <fstream>
#include <sstream>
#include <iostream>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <chrono>
#include <dirent.h>
#include <condition_variable>
#include <vector>
#include "include/securec.h"
#include "string_util.h"
using
namespace
OHOS
::
HiviewDFX
;
int
ExecCmdWithRet
(
std
::
string
cmd
,
std
::
vector
<
std
::
string
>
&
resvec
)
{
if
(
cmd
.
size
()
==
0
)
{
return
0
;
}
std
::
cout
<<
"cmd is "
+
cmd
<<
std
::
endl
;
if
((
cmd
.
find
(
"hilog"
)
==
std
::
string
::
npos
)
&&
(
cmd
.
find
(
"hidumper"
)
==
std
::
string
::
npos
)
&&
(
cmd
.
find
(
"ps"
)
==
std
::
string
::
npos
)
&&
(
cmd
.
find
(
"rm"
)
==
std
::
string
::
npos
)
&&
(
cmd
.
find
(
"hiperf"
)
==
std
::
string
::
npos
)
&&
(
cmd
.
find
(
"hisysevent"
)
==
std
::
string
::
npos
)
&&
(
cmd
.
find
(
"mkdir"
)
==
std
::
string
::
npos
)
&&
(
cmd
.
find
(
"dd"
)
==
std
::
string
::
npos
))
{
std
::
cout
<<
"unsupport cmd!"
+
cmd
<<
std
::
endl
;
return
0
;
}
resvec
.
clear
();
FILE
*
pp
=
popen
(
cmd
.
c_str
(),
"r"
);
if
(
pp
==
nullptr
)
{
return
-
1
;
}
char
tmp
[
1024
];
while
(
fgets
(
tmp
,
sizeof
(
tmp
),
pp
)
!=
nullptr
)
{
if
(
tmp
[
strlen
(
tmp
)
-
1
]
==
'\n'
)
{
tmp
[
strlen
(
tmp
)
-
1
]
=
'\0'
;
}
resvec
.
push_back
(
tmp
);
}
pclose
(
pp
);
return
resvec
.
size
();
}
void
ExeCmd
(
std
::
string
cmd
)
{
std
::
vector
<
std
::
string
>
cmdret
;
ExecCmdWithRet
(
cmd
,
cmdret
);
}
void
CmdRun
(
std
::
string
cmd
,
std
::
string
&
result
)
{
std
::
vector
<
std
::
string
>
cmdret
;
int
resultlen
;
int
i
=
0
;
std
::
string
rst
;
resultlen
=
ExecCmdWithRet
(
cmd
,
cmdret
);
while
(
i
<
resultlen
)
{
rst
=
rst
+
cmdret
[
i
];
i
=
i
+
1
;
}
result
=
rst
;
}
void
CleanCmd
()
{
std
::
string
cmdResult
;
std
::
string
cleanCmd
=
"hilog -r"
;
CmdRun
(
cleanCmd
,
cmdResult
);
std
::
cout
<<
cmdResult
;
}
std
::
string
ExecuteCmd
(
std
::
string
cmd
)
{
std
::
vector
<
std
::
string
>
cmdret
;
int
resultlen
;
int
i
=
0
;
std
::
string
rst
;
resultlen
=
ExecCmdWithRet
(
cmd
,
cmdret
);
while
(
i
<
resultlen
)
{
rst
=
rst
+
cmdret
[
i
]
+
"
\n
"
;
i
=
i
+
1
;
}
return
rst
;
}
void
SaveCmdOutput
(
std
::
string
cmd
,
std
::
string
saveFile
)
{
std
::
fstream
fstr
(
saveFile
,
std
::
ios
::
out
);
std
::
string
cmdRet
=
ExecuteCmd
(
cmd
);
fstr
<<
cmdRet
;
fstr
.
close
();
}
void
RedirecthiLog
(
std
::
string
&
hilogredirect
,
std
::
string
&
timeout
)
{
unsigned
long
i
;
std
::
vector
<
std
::
string
>
cmdret
;
unsigned
long
cmdretlen
;
std
::
string
cmd
=
"rm "
+
hilogredirect
;
cmdretlen
=
ExecCmdWithRet
(
cmd
,
cmdret
);
for
(
i
=
0
;
i
<
cmdretlen
;
i
++
)
{
std
::
cout
<<
cmdret
[
i
].
c_str
()
<<
std
::
endl
;
}
cmd
=
"timeout "
+
timeout
+
" hilog >"
+
hilogredirect
;
std
::
cout
<<
cmd
<<
std
::
endl
;
cmdretlen
=
ExecCmdWithRet
(
cmd
,
cmdret
);
for
(
i
=
0
;
i
<
cmdretlen
;
i
++
)
{
std
::
cout
<<
cmdret
[
i
].
c_str
()
<<
std
::
endl
;
}
}
bool
CheckInfo
(
std
::
vector
<
std
::
string
>
&
para
,
std
::
string
info
)
{
if
(
info
.
empty
())
{
return
false
;
}
bool
result
=
false
;
unsigned
long
matchcnt
=
0
;
for
(
unsigned
long
i
=
0
;
i
<
para
.
size
();
i
++
)
{
if
(
int
(
info
.
find
(
para
[
i
]))
>=
0
)
{
matchcnt
++
;
}
}
std
::
cout
<<
matchcnt
<<
std
::
endl
;
if
(
matchcnt
==
para
.
size
())
{
result
=
true
;
}
return
result
;
}
bool
CompareString
(
const
std
::
string
&
x
,
const
std
::
string
&
y
)
{
int
len
=
x
.
length
()
-
1
;
while
(
x
[
len
]
==
y
[
len
]
&&
len
>=
0
)
{
len
--
;
}
if
(
len
>=
0
&&
x
[
len
]
>
y
[
len
])
{
return
false
;
}
return
true
;
}
int
GetTxtLine
(
std
::
string
filename
)
{
FILE
*
fd
=
fopen
(
filename
.
c_str
(),
"r"
);
int
count
=
0
;
if
(
fd
!=
nullptr
)
{
while
(
!
feof
(
fd
))
{
if
(
fgetc
(
fd
)
==
'\n'
)
{
count
++
;
}
}
}
std
::
cout
<<
count
<<
std
::
endl
;
if
(
fd
!=
nullptr
)
{
fclose
(
fd
);
}
return
count
;
}
std
::
string
ReadFile
(
std
::
string
filename
)
{
std
::
ifstream
ifile
(
filename
);
std
::
ostringstream
buf
;
char
ch
;
if
(
ifile
.
fail
())
{
std
::
cout
<<
"open file fail!"
<<
std
::
endl
;
return
""
;
}
while
(
buf
&&
ifile
.
get
(
ch
))
{
buf
.
put
(
ch
);
}
ifile
.
close
();
return
buf
.
str
();
}
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
0 → 100755
浏览文件 @
ca556c4d
/*
* Copyright (C) 2021-2022 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 HIVIEWDFX_UTILS_NATIVE_FILE_UTILS_H_
#define HIVIEWDFX_UTILS_NATIVE_FILE_UTILS_H_
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <fstream>
#include <sstream>
#include <iostream>
#include <chrono>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <dirent.h>
#include <vector>
bool
CheckInfo
(
std
::
vector
<
std
::
string
>
&
para
,
std
::
string
eventinfo
);
int
ExecCmdWithRet
(
std
::
string
cmd
,
std
::
vector
<
std
::
string
>
&
resvec
);
std
::
string
ReadFile
(
std
::
string
filename
);
void
RedirecthiLog
(
std
::
string
&
hilogredirect
,
std
::
string
&
timeout
);
void
ExeCmd
(
std
::
string
cmd
);
void
CmdRun
(
std
::
string
cmd
,
std
::
string
&
result
);
std
::
string
ExecuteCmd
(
std
::
string
cmd
);
bool
CompareString
(
const
std
::
string
&
x
,
const
std
::
string
&
y
);
int
GetTxtLine
(
std
::
string
filename
);
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 // HIVIEWDFX_UTILS_NATIVE_FILE_UTILS_H_
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录