Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Test Developertest
提交
3403ce44
T
Test Developertest
项目概览
OpenHarmony
/
Test Developertest
大约 1 年 前同步成功
通知
2
Star
23
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
Test Developertest
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
3403ce44
编写于
4月 11, 2022
作者:
O
openharmony_ci
提交者:
Gitee
4月 11, 2022
浏览文件
操作
浏览文件
下载
差异文件
!99 Modified the Fuzzer's File
Merge pull request !99 from stivn/master
上级
7cee1ad3
e55fe2c2
变更
8
隐藏空白更改
内联
并排
Showing
8 changed file
with
38 addition
and
74 deletion
+38
-74
examples/calculator/test/fuzztest/common/Calculator_fuzzer/BUILD.gn
...alculator/test/fuzztest/common/Calculator_fuzzer/BUILD.gn
+2
-2
examples/calculator/test/fuzztest/common/Calculator_fuzzer/Calculator_fuzzer.cpp
...t/fuzztest/common/Calculator_fuzzer/Calculator_fuzzer.cpp
+0
-0
examples/calculator/test/fuzztest/common/Calculator_fuzzer/Calculator_fuzzer.h
...est/fuzztest/common/Calculator_fuzzer/Calculator_fuzzer.h
+4
-4
examples/calculator/test/fuzztest/common/Calculator_fuzzer/corpus/init
...ulator/test/fuzztest/common/Calculator_fuzzer/corpus/init
+0
-0
examples/calculator/test/fuzztest/common/Calculator_fuzzer/project.xml
...ulator/test/fuzztest/common/Calculator_fuzzer/project.xml
+0
-0
libs/fuzzlib/README_zh.md
libs/fuzzlib/README_zh.md
+15
-41
src/core/driver/drivers.py
src/core/driver/drivers.py
+6
-4
src/core/utils.py
src/core/utils.py
+11
-23
未找到文件。
examples/calculator/test/fuzztest/common/
parse
_fuzzer/BUILD.gn
→
examples/calculator/test/fuzztest/common/
Calculator
_fuzzer/BUILD.gn
浏览文件 @
3403ce44
...
...
@@ -19,7 +19,7 @@ module_output_path = "developertest/calculator"
##############################fuzztest##########################################
ohos_fuzztest("CalculatorFuzzTest") {
module_out_path = module_output_path
fuzz_config_file = "//test/developertest/examples/calculator/test/fuzztest/common/Calculator_fuzzer"
include_dirs = []
cflags = [
"-g",
...
...
@@ -27,7 +27,7 @@ ohos_fuzztest("CalculatorFuzzTest") {
"-Wno-unused-variable",
"-fno-omit-frame-pointer",
]
sources = [ "
parse
_fuzzer.cpp" ]
sources = [ "
Calculator
_fuzzer.cpp" ]
}
###############################################################################
...
...
examples/calculator/test/fuzztest/common/
parse_fuzzer/parse
_fuzzer.cpp
→
examples/calculator/test/fuzztest/common/
Calculator_fuzzer/Calculator
_fuzzer.cpp
浏览文件 @
3403ce44
文件已移动
examples/calculator/test/fuzztest/common/
parse_fuzzer/parse
_fuzzer.h
→
examples/calculator/test/fuzztest/common/
Calculator_fuzzer/Calculator
_fuzzer.h
浏览文件 @
3403ce44
...
...
@@ -13,9 +13,9 @@
* limitations under the License.
*/
#ifndef
_EXAMPLE_CALCULATOR_PARSE
_FUZZER_H_
#define
_EXAMPLE_CALCULATOR_PARSE
_FUZZER_H_
#ifndef
EXAMPLE_CALCULATOR
_FUZZER_H_
#define
EXAMPLE_CALCULATOR
_FUZZER_H_
#define FUZZ_PROJECT_NAME "
parse
_fuzzer"
#define FUZZ_PROJECT_NAME "
Calculator
_fuzzer"
#endif // _EXAMPLE_CALCULATOR_PARSE_FUZZER_H_
\ No newline at end of file
#endif // EXAMPLE_CALCULATOR_FUZZER_H_
\ No newline at end of file
examples/calculator/test/fuzztest/common/
parse
_fuzzer/corpus/init
→
examples/calculator/test/fuzztest/common/
Calculator
_fuzzer/corpus/init
浏览文件 @
3403ce44
文件已移动
examples/calculator/test/fuzztest/common/
parse
_fuzzer/project.xml
→
examples/calculator/test/fuzztest/common/
Calculator
_fuzzer/project.xml
浏览文件 @
3403ce44
文件已移动
libs/fuzzlib/README_zh.md
浏览文件 @
3403ce44
...
...
@@ -53,12 +53,12 @@ Fuzzing测试框架使用了LLVM编译器框架中的[libFuzzer](https://llvm.or
执行gen命令用于fuzzer源文件生成,会自动生成fuzzer源文件、fuzzer配置文件和corpus语料,目录结构如下
```
parse
_fuzzer/
Calculator
_fuzzer/
├── corpus # Fuzz语料目录
│ ├── init # Fuzz语料
├── BUILD.gn # Fuzz用例编译配置
├──
parse
_fuzzer.cpp # Fuzz用例源文件
├──
parse
_fuzzer.h # Fuzz用例头文件
├──
Calculator
_fuzzer.cpp # Fuzz用例源文件
├──
Calculator
_fuzzer.h # Fuzz用例头文件
├── project.xml # Fuzz选项配置文件
```
...
...
@@ -71,13 +71,13 @@ Fuzzing测试框架使用了LLVM编译器框架中的[libFuzzer](https://llvm.or
| 参数 | 描述 | 说明 | 备注 |
| ---- | ---------- | -------------- | ------------------------------------------ |
| -t | testtype | 测试类型 | 目前仅支持"FUZZ" |
| -fn | fuzzername | fuzzer名称 | 为显式区分Fuzz用例,名称必须以
"fuzzer"结尾
|
| -fn | fuzzername | fuzzer名称 | 为显式区分Fuzz用例,名称必须以
测试套前缀 + _fuzzer形式命名
|
| -dp | dirpath | fuzzer生成路径 | 路径不存在则自动创建目录 |
3.
gen命令示例,-t、-fn和-dp均为必选项
```
gen -t FUZZ -fn
parse
_fuzzer -dp test/developertest/example/calculator/test/fuzztest/common
gen -t FUZZ -fn
Calculator
_fuzzer -dp test/developertest/example/calculator/test/fuzztest/common
```
执行完毕后会在test/developertest/example/calculator/test/fuzztest/common目录下生成一个Fuzz用例demo。
...
...
@@ -100,7 +100,7 @@ Fuzzing测试框架使用了LLVM编译器框架中的[libFuzzer](https://llvm.or
!
[
img
](
../../public_sys-resources/icon-note.gif
)
**说明:**
DoSomethingInterestingWithMyAPI接口名称允许依据业务逻辑修改。两接口参数data和size为fuzz测试标准化参数,不可修改。
```
#include "
parse
_fuzzer.h"
#include "
Calculator
_fuzzer.h"
#include <stddef.h>
#include <stdint.h>
...
...
@@ -143,7 +143,7 @@ Fuzzing测试框架使用了LLVM编译器框架中的[libFuzzer](https://llvm.or
```
ohos_fuzztest("CalculatorFuzzTest") { #定义测试套名称CalculatorFuzzTest
module_out_path = module_output_path
fuzz_config_file = "//test/developertest/examples/calculator/test/fuzztest/common/Calculator_fuzzer"
include_dirs = []
cflags = [
"-g",
...
...
@@ -151,7 +151,7 @@ Fuzzing测试框架使用了LLVM编译器框架中的[libFuzzer](https://llvm.or
"-Wno-unused-variable",
"-fno-omit-frame-pointer",
]
sources = [ "
parse
_fuzzer.cpp" ]
sources = [ "
Calculator
_fuzzer.cpp" ]
}
```
...
...
@@ -209,7 +209,7 @@ Fuzzing测试框架使用了LLVM编译器框架中的[libFuzzer](https://llvm.or
testonly = true
deps = []
deps += [ "fuzztest/common/
parse
_fuzzer:fuzztest" ]
deps += [ "fuzztest/common/
Calculator
_fuzzer:fuzztest" ]
}
```
...
...
@@ -233,55 +233,29 @@ run -t FUZZ -ss developertest -tm calculator
Windows环境可通过归档DTFuzz用例配置文件project.xml、语料corpus和可执行文件执行DTFuzz。
1.
归档用例配置文件、语料
1.
归档用例配置文件、语料
以及用例可执行文件
新建目录,如:
```
D:\test\
res\parse_fuzzer
D:\test\
tests
```
parse_fuzzer用例的配置文件project.xml、语料corpus拷贝到该路径下。如有多个需要执行的用例,在res目录下新建多个xxx_fuzzer目录。
2.
归档用例可执行文件
用例可执行文件为DTFuzz源文件编译产出文件,为DTFuzz用例在设备中实际执行文件,以二进制形式存储在out/release/package/phone/tests/fuzztest下,名称为对应的测试套名。测试套的配置文件均编译输出在out/release/package/phone/tests/res目录下对应的XXXX_fuzzer目录中。将编译生成的配置文件res目录以及用例可执行文件fuzztest目录直接拷贝到该路径下即可。
用例可执行文件为DTFuzz源文件编译产出文件,为DTFuzz用例在设备中实际执行文件,以二进制形式存储在out/release/package/phone/tests/fuzztest下,名称为对应的测试套名。
新建目录,如:
```
D:\test\cases
```
将fuzztest目录拷贝到该路径下。
3.
配置执行用例
libs
\f
uzzlib中新建fuzzer_list.txt,其中配置需要执行的DTFuzz用例,如需要执行parse_fuzzer用例:
```
#格式:用例配置文件和语料归档路径 可执行文件名
D:\test\res\parse_fuzzer CalculatorFuzzTest
```
!
[
img
](
../../public_sys-resources/icon-note.gif
)
**说明:**
1.
fuzzer_list.txt中可配置多行,每行对应一个DTFuzz用例
2.
路径与可执行文件名严格一一对应,如例子中路径归档的是parse_fuzzer用例的配置文件和语料,CalculatorFuzzTest为parse_fuzzer用例的可执行文件。
4.
配置用例路径
2.
配置用例路径
config
\u
ser_config.xml中配置用例归档路径:
```
<!-- configure test cases path -->
<test_cases>
<dir>D:\test\
case
s</dir> #用例可执行文件归档路径
<dir>D:\test\
test
s</dir> #用例可执行文件归档路径
</test_cases>
```
5
.
执行用例
3
.
执行用例
执行DTFuzz命令示例,无需参数-ss、-tm
...
...
src/core/driver/drivers.py
浏览文件 @
3403ce44
...
...
@@ -481,12 +481,13 @@ class CppTestDriver(IDriver):
self
.
config
.
testlevel
,
self
.
config
.
testtype
,
self
.
config
.
target_test_path
,
suite_file
,
filename
)
is_coverage_test
=
True
if
self
.
config
.
coverage
else
False
# push testsuite file
self
.
config
.
device
.
push_file
(
suite_file
,
self
.
config
.
target_test_path
)
self
.
_push_corpus_if_exist
(
filenam
e
)
self
.
_push_corpus_if_exist
(
suite_fil
e
)
# push resource files
resource_manager
=
ResourceManager
()
...
...
@@ -533,9 +534,9 @@ class CppTestDriver(IDriver):
resource_dir
,
self
.
config
.
device
)
def
_push_corpus_if_exist
(
self
,
filenam
e
):
def
_push_corpus_if_exist
(
self
,
suite_fil
e
):
if
"fuzztest"
==
self
.
config
.
testtype
[
0
]:
corpus_path
=
os
.
path
.
join
(
get_fuzzer_path
(
filenam
e
),
"corpus"
)
corpus_path
=
os
.
path
.
join
(
get_fuzzer_path
(
suite_fil
e
),
"corpus"
)
self
.
config
.
device
.
push_file
(
corpus_path
,
os
.
path
.
join
(
self
.
config
.
target_test_path
,
"corpus"
))
...
...
@@ -544,6 +545,7 @@ class CppTestDriver(IDriver):
testlevel
,
testtype
,
target_test_path
,
suite_file
,
filename
):
if
"benchmark"
==
testtype
[
0
]:
test_para
=
(
" --benchmark_out_format=json"
...
...
@@ -561,7 +563,7 @@ class CppTestDriver(IDriver):
if
"fuzztest"
==
testtype
[
0
]:
cfg_list
=
FuzzerConfigManager
(
os
.
path
.
join
(
get_fuzzer_path
(
filenam
e
),
"project.xml"
)).
get_fuzzer_config
(
"fuzztest"
)
suite_fil
e
),
"project.xml"
)).
get_fuzzer_config
(
"fuzztest"
)
LOG
.
info
(
"config list :%s"
%
str
(
cfg_list
))
test_para
+=
"corpus -max_len="
+
cfg_list
[
0
]
+
\
" -max_total_time="
+
cfg_list
[
1
]
+
\
...
...
src/core/utils.py
浏览文件 @
3403ce44
...
...
@@ -173,29 +173,17 @@ def get_decode(stream):
return
ret
def
parse_fuzzer_info
():
path_list
=
[]
bin_list
=
[]
list_path
=
os
.
path
.
join
(
os
.
path
.
dirname
(
os
.
path
.
dirname
(
os
.
path
.
dirname
(
os
.
path
.
realpath
(
__file__
)))),
"libs"
,
"fuzzlib"
,
"fuzzer_list.txt"
)
with
open
(
list_path
,
'r'
)
as
list_file
:
for
line
in
list_file
.
readlines
():
striped_str
=
line
.
strip
()
if
platform
.
system
()
==
"Windows"
:
path_list
.
append
(
striped_str
.
split
(
" "
)[
0
])
bin_list
.
append
(
striped_str
.
split
(
" "
)[
1
])
else
:
path_list
.
append
(
striped_str
.
split
(
":"
)[
0
][
3
:])
bin_list
.
append
(
striped_str
.
split
(
":"
)[
1
].
split
(
"("
)[
0
])
return
path_list
,
bin_list
def
get_fuzzer_path
(
filename
):
path_list
,
bin_list
=
parse_fuzzer_info
()
for
i
,
name
in
enumerate
(
bin_list
):
if
name
==
filename
:
return
os
.
path
.
join
(
sys
.
source_code_root_path
,
path_list
[
i
])
return
""
def
get_fuzzer_path
(
suite_file
):
filename
=
os
.
path
.
basename
(
suite_file
)
suitename
=
filename
.
split
(
"FuzzTest"
)[
0
]
current_dir
=
os
.
path
.
dirname
(
suite_file
)
while
True
:
if
os
.
path
.
exists
(
os
.
path
.
join
(
current_dir
,
"tests"
)):
res_path
=
os
.
path
.
join
(
os
.
path
.
join
(
current_dir
,
"tests"
),
"res"
)
break
current_dir
=
os
.
path
.
dirname
(
current_dir
)
fuzzer_path
=
os
.
path
.
join
(
res_path
,
"%s_fuzzer"
%
suitename
)
return
fuzzer_path
def
is_lite_product
(
product_form
,
code_root_path
):
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录