diff --git a/aw/python/distributed/common/devices.py b/aw/python/distributed/common/devices.py index 71803853a2ce9850decf534a9784254117ef9ade..e900160f41375835feb63ab7858a3da69574ff6a 100755 --- a/aw/python/distributed/common/devices.py +++ b/aw/python/distributed/common/devices.py @@ -179,7 +179,6 @@ class DeviceAdapter: time.sleep(1) return return_code - ############################################################### ############################################################### @@ -199,6 +198,7 @@ class DeviceAdapter: remote_ip, remote_port, device_sn) return device_para + @classmethod def execute_command(self, command, print_flag=True, timeout=900): try: if print_flag: @@ -211,6 +211,7 @@ class DeviceAdapter: print("results: failed") return False + @classmethod def execute_command_with_output(self, command, print_flag=True): if print_flag: print("command: " + command) @@ -248,6 +249,7 @@ class DeviceAdapter: command, QUOTATION_MARKS)) + @classmethod def check_path_legal(self, path): if path and " " in path: return "\"%s\"" % path @@ -318,7 +320,6 @@ class HDCDeviceAdapter: self.unlock_screen() self.unlock_device() - ############################################################### ############################################################### @@ -337,7 +338,7 @@ class HDCDeviceAdapter: device_para = "-s tcp:%s:%s -t %s" % ( remote_ip, remote_port, device_sn) return device_para - + @classmethod def execute_command(self, command, print_flag=True, timeout=900): try: if print_flag: @@ -350,6 +351,7 @@ class HDCDeviceAdapter: print("results: failed") return False + @classmethod def execute_command_with_output(self, command, print_flag=True): if print_flag: print("command: " + command) @@ -384,6 +386,7 @@ class HDCDeviceAdapter: command, QUOTATION_MARKS)) + @classmethod def check_path_legal(self, path): if path and " " in path: return "\"%s\"" % path diff --git a/aw/python/distributed/common/manager.py b/aw/python/distributed/common/manager.py index 7d3f3e977d75f4ae5b3651c3dded7bf7191ba4e5..0cba2d64702705a9deb575fd4e209ba8f5a4bba4 100755 --- a/aw/python/distributed/common/manager.py +++ b/aw/python/distributed/common/manager.py @@ -79,6 +79,7 @@ class DeviceManager: setattr(self, device.name, device) return + @classmethod def get_device_info_list(self): device_info_list = [] tmp_path = os.path.join(os.environ.get('PYTEST_RESULTPATH'), "temp") diff --git a/aw/python/distributed/distribute/distribute.py b/aw/python/distributed/distribute/distribute.py index 10790d05d1050f93688c8d399e19c66f0a699b7b..29b0d8becba926d5402d9cb855be971f412c7abd 100755 --- a/aw/python/distributed/distribute/distribute.py +++ b/aw/python/distributed/distribute/distribute.py @@ -116,6 +116,7 @@ class Distribute: suite_path = os.path.join(self.suite_dir, target_name) return driver.execute(suite_path, background=False) + @classmethod def pull_result(self, device, source_path, result_save_path): _, file_name = os.path.split(source_path) device.pull_file(source_path, result_save_path) @@ -123,6 +124,7 @@ class Distribute: create_empty_result_file(result_save_path, file_name) return + @classmethod def _check_thread(self, device, thread_name): check_command = "ps -A | grep %s" % thread_name checksum = 0 @@ -164,6 +166,7 @@ class Distribute: config_major_file = os.path.join(self.suite_dir, "major.desc") self._write_device_config(config_info, config_major_file) + @classmethod def _query_device_ip(self, device): output = device.shell_with_output("getprop ro.hardware") if output == "": @@ -185,6 +188,7 @@ class Distribute: return ipaddress[0] + @classmethod def _query_device_uuid(self, device): """ 1. Run the dumpsys DdmpDeviceMonitorService command to query the value @@ -209,6 +213,7 @@ class Distribute: dev_nodeid_info = device_info[begin:end].replace('"', "") return dev_nodeid_info.split(":")[1] + @classmethod def _write_device_config(self, device_info, file_path): file_dir, file_name = os.path.split(file_path) final_file = os.path.join(file_dir, file_name.split('.')[0] + ".desc") diff --git a/examples/app_info/test/unittest/common/get_app_info/ExampleJsunit.test.js b/examples/app_info/test/unittest/common/get_app_info/ExampleJsunit.test.js index d6e92a7a6a5204f8b0718e09f72c44a045f2d572..84f768238335f1af1fdd4d7aa1bb5fd9d3a60c17 100644 --- a/examples/app_info/test/unittest/common/get_app_info/ExampleJsunit.test.js +++ b/examples/app_info/test/unittest/common/get_app_info/ExampleJsunit.test.js @@ -18,6 +18,7 @@ import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from ' describe("AppInfoTest", function () { beforeAll(function() { + /* * @tc.setup: setup invoked before all testcases */ @@ -25,6 +26,7 @@ describe("AppInfoTest", function () { }) afterAll(function() { + /* * @tc.teardown: teardown invoked after all testcases */ @@ -32,6 +34,7 @@ describe("AppInfoTest", function () { }) beforeEach(function() { + /* * @tc.setup: setup invoked before each testcases */ @@ -39,6 +42,7 @@ describe("AppInfoTest", function () { }) afterEach(function() { + /* * @tc.teardown: teardown invoked after each testcases */ diff --git a/examples/calculator/test/BUILD.gn b/examples/calculator/test/BUILD.gn index c63fcc58a6ededf8318016c9a04f68cd2923ea5b..00aa30c43299d9bcc66960a8a5cc9829848bc48f 100755 --- a/examples/calculator/test/BUILD.gn +++ b/examples/calculator/test/BUILD.gn @@ -29,7 +29,7 @@ group("fuzztest") { testonly = true deps = [] - deps += [ "fuzztest/common/parse_fuzzer:fuzztest" ] + deps += [ "fuzztest/common/calculator_fuzzer:fuzztest" ] } group("benchmarktest") { diff --git a/examples/calculator/test/fuzztest/common/parse_fuzzer/BUILD.gn b/examples/calculator/test/fuzztest/common/Calculator_fuzzer/BUILD.gn similarity index 89% rename from examples/calculator/test/fuzztest/common/parse_fuzzer/BUILD.gn rename to examples/calculator/test/fuzztest/common/Calculator_fuzzer/BUILD.gn index bfdc2202c82c162db4ca8fb5e4d1622cf19dbcb6..45b78fd75ebeec0f4eb2b00a397a73d4c24f017e 100644 --- a/examples/calculator/test/fuzztest/common/parse_fuzzer/BUILD.gn +++ b/examples/calculator/test/fuzztest/common/Calculator_fuzzer/BUILD.gn @@ -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" ] } ############################################################################### diff --git a/examples/calculator/test/fuzztest/common/parse_fuzzer/parse_fuzzer.cpp b/examples/calculator/test/fuzztest/common/Calculator_fuzzer/Calculator_fuzzer.cpp similarity index 100% rename from examples/calculator/test/fuzztest/common/parse_fuzzer/parse_fuzzer.cpp rename to examples/calculator/test/fuzztest/common/Calculator_fuzzer/Calculator_fuzzer.cpp diff --git a/examples/calculator/test/fuzztest/common/parse_fuzzer/parse_fuzzer.h b/examples/calculator/test/fuzztest/common/Calculator_fuzzer/Calculator_fuzzer.h similarity index 77% rename from examples/calculator/test/fuzztest/common/parse_fuzzer/parse_fuzzer.h rename to examples/calculator/test/fuzztest/common/Calculator_fuzzer/Calculator_fuzzer.h index 9089dfa2f553ae84b1edb15f262ef001320235da..83d6f5592719ea49d5867d32b0bfd4c9b7130c29 100644 --- a/examples/calculator/test/fuzztest/common/parse_fuzzer/parse_fuzzer.h +++ b/examples/calculator/test/fuzztest/common/Calculator_fuzzer/Calculator_fuzzer.h @@ -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 diff --git a/examples/calculator/test/fuzztest/common/parse_fuzzer/corpus/init b/examples/calculator/test/fuzztest/common/Calculator_fuzzer/corpus/init similarity index 93% rename from examples/calculator/test/fuzztest/common/parse_fuzzer/corpus/init rename to examples/calculator/test/fuzztest/common/Calculator_fuzzer/corpus/init index 4dc63c8f403b1fa695180b46d78e22021ec1cd04..59aefb51c6e5a670d20c9bda3030fcdf8db29e5a 100644 --- a/examples/calculator/test/fuzztest/common/parse_fuzzer/corpus/init +++ b/examples/calculator/test/fuzztest/common/Calculator_fuzzer/corpus/init @@ -9,4 +9,5 @@ # 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. \ No newline at end of file +# limitations under the License. +FUZZ \ No newline at end of file diff --git a/examples/calculator/test/fuzztest/common/parse_fuzzer/project.xml b/examples/calculator/test/fuzztest/common/Calculator_fuzzer/project.xml similarity index 100% rename from examples/calculator/test/fuzztest/common/parse_fuzzer/project.xml rename to examples/calculator/test/fuzztest/common/Calculator_fuzzer/project.xml diff --git a/examples/calculator/test/fuzztest/common/calculator_fuzzer/BUILD.gn b/examples/calculator/test/fuzztest/common/calculator_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..45b78fd75ebeec0f4eb2b00a397a73d4c24f017e --- /dev/null +++ b/examples/calculator/test/fuzztest/common/calculator_fuzzer/BUILD.gn @@ -0,0 +1,43 @@ +# 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("//build/config/features.gni") +import("//build/test.gni") + +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", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "calculator_fuzzer.cpp" ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [] + + deps += [ + # deps file + ":CalculatorFuzzTest", + ] +} +############################################################################### diff --git a/examples/calculator/test/fuzztest/common/calculator_fuzzer/calculator_fuzzer.cpp b/examples/calculator/test/fuzztest/common/calculator_fuzzer/calculator_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..beead983a4a1e81b5ad1837869849d7d71797503 --- /dev/null +++ b/examples/calculator/test/fuzztest/common/calculator_fuzzer/calculator_fuzzer.cpp @@ -0,0 +1,50 @@ +/* + * 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 +#include + +const int FUZZ_DATA_LEN = 3; +const int FUZZ_FST_DATA = 0; +const int FUZZ_SND_DATA = 1; +const int FUZZ_TRD_DATA = 2; +const int FUZZ_FTH_DATA = 3; + +namespace OHOS { + bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size) + { + if (data == nullptr) { + return false; + } + + bool result = false; + if (size >= FUZZ_DATA_LEN) { + result = data[FUZZ_FST_DATA] == 'F' && + data[FUZZ_SND_DATA] == 'U' && + data[FUZZ_TRD_DATA] == 'Z' && + data[FUZZ_FTH_DATA] == 'Z'; + } + return result; + } +} // namespace.OHOS + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::DoSomethingInterestingWithMyAPI(data, size); + return 0; +} + diff --git a/examples/calculator/test/fuzztest/common/calculator_fuzzer/calculator_fuzzer.h b/examples/calculator/test/fuzztest/common/calculator_fuzzer/calculator_fuzzer.h new file mode 100644 index 0000000000000000000000000000000000000000..83d6f5592719ea49d5867d32b0bfd4c9b7130c29 --- /dev/null +++ b/examples/calculator/test/fuzztest/common/calculator_fuzzer/calculator_fuzzer.h @@ -0,0 +1,21 @@ +/* + * 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 EXAMPLE_CALCULATOR_FUZZER_H_ +#define EXAMPLE_CALCULATOR_FUZZER_H_ + +#define FUZZ_PROJECT_NAME "calculator_fuzzer" + +#endif // EXAMPLE_CALCULATOR_FUZZER_H_ \ No newline at end of file diff --git a/examples/calculator/test/fuzztest/common/calculator_fuzzer/corpus/init b/examples/calculator/test/fuzztest/common/calculator_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..59aefb51c6e5a670d20c9bda3030fcdf8db29e5a --- /dev/null +++ b/examples/calculator/test/fuzztest/common/calculator_fuzzer/corpus/init @@ -0,0 +1,13 @@ +# Copyright (c) 2020-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. +FUZZ \ No newline at end of file diff --git a/examples/calculator/test/fuzztest/common/calculator_fuzzer/project.xml b/examples/calculator/test/fuzztest/common/calculator_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..85e7ef2c1cc6471e288306f6e3dcea5287a78b0e --- /dev/null +++ b/examples/calculator/test/fuzztest/common/calculator_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/examples/distributedb/test/BUILD.gn b/examples/distributedb/test/BUILD.gn index bad399b5b3903ea52293d48c6580a870c88a4308..0bf3b10b0fe7c0a4bdb1babe3784cf4786c72d28 100755 --- a/examples/distributedb/test/BUILD.gn +++ b/examples/distributedb/test/BUILD.gn @@ -51,7 +51,7 @@ ohos_distributedtest("DistributeDemo") { ] deps = [ - "//foundation/distributeddatamgr/distributeddatamgr/interfaces/innerkits/app_distributeddata/:app_distributeddata", + "//foundation/distributeddatamgr/distributeddatamgr/interfaces/innerkits/distributeddata/:distributeddata_inner", "//foundation/distributeddatamgr/distributeddatamgr/services/distributeddataservice/adapter:distributeddata_adapter", "//third_party/googletest:gtest", "//utils/native/base:utils", @@ -73,7 +73,7 @@ ohos_distributedtest("DistributeDemoAgent") { ] deps = [ - "//foundation/distributeddatamgr/distributeddatamgr/interfaces/innerkits/app_distributeddata/:app_distributeddata", + "//foundation/distributeddatamgr/distributeddatamgr/interfaces/innerkits/distributeddata/:distributeddata_inner", "//foundation/distributeddatamgr/distributeddatamgr/services/distributeddataservice/adapter:distributeddata_adapter", "//third_party/googletest:gtest", "//utils/native/base:utils", diff --git a/libs/fuzzlib/README_zh.md b/libs/fuzzlib/README_zh.md index 3d52e2ceb5dcaf7c7edda7f10507bbcecc748529..97f9c1ff8e8f226f431a9f152b990ba75f403231 100644 --- a/libs/fuzzlib/README_zh.md +++ b/libs/fuzzlib/README_zh.md @@ -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 #include @@ -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" ] } ``` @@ -168,7 +168,9 @@ Fuzzing测试框架使用了LLVM编译器框架中的[libFuzzer](https://llvm.or ] } ``` - + **注意:** + - 测试套名称采用大驼峰风格,并且以FuzzTest结尾,测试套前缀与fuzzer目录名相对应。 + - module_out_path为测试套编译输出目录,内容为部件+模块名。 3. Fuzz配置编写 @@ -190,10 +192,10 @@ Fuzzing测试框架使用了LLVM编译器框架中的[libFuzzer](https://llvm.or 添加Fuzz用例编译到模块的test_list中: -1. 在需要DTFuzz测试的对应模块ohos.build添加Fuzz用例路径,如在examples/ohos.build添加: +1. 在需要DTFuzz测试的对应模块bundle.json中添加Fuzz用例路径,如在bundle.json添加: ``` - "test_list": [ + "tests": [ "//test/developertest/examples/calculator/test:unittest", "//test/developertest/examples/calculator/test:fuzztest", #添加DTFuzz用例路径 "//test/developertest/examples/detector/test:unittest", @@ -209,7 +211,7 @@ Fuzzing测试框架使用了LLVM编译器框架中的[libFuzzer](https://llvm.or testonly = true deps = [] - deps += [ "fuzztest/common/parse_fuzzer:fuzztest" ] + deps += [ "fuzztest/common/calculator_fuzzer:fuzztest" ] } ``` @@ -233,60 +235,35 @@ 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源文件编译产出文件,以二进制形式存储在out/release/package/phone/tests/fuzztest下。测试用例的配置文件均编译输出在out/release/package/phone/tests/res目录下对应的xxxx_fuzzer目录中。 + 将fuzztest目录以及res目录直接拷贝到该路径下即可。 - 用例可执行文件为DTFuzz源文件编译产出文件,为DTFuzz用例在设备中实际执行文件,以二进制形式存储在out/release/package/phone/tests/fuzztest下,名称为对应的测试套名。 - - 新建目录,如: - - ``` - D:\test\cases - ``` - - 将fuzztest目录拷贝到该路径下。 - 3. 配置执行用例 - - libs\fuzzlib中新建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\user_config.xml中配置用例归档路径: ``` - D:\test\cases #用例可执行文件归档路径 + D:\test\tests #用例可执行文件归档路径 ``` - 5. 执行用例 + 3. 执行用例 - 执行DTFuzz命令示例,无需参数-ss、-tm + 执行DTFuzz命令示例 ``` - run -t FUZZ + run -t FUZZ -ts CalculatorFuzzTest ``` diff --git a/libs/fuzzlib/fuzzer_helper.py b/libs/fuzzlib/fuzzer_helper.py index b8c6217419047f2c6d31f1a22b6e03b4c5b3d2f9..75efdfbb8981439f9b8092a2d048ff8d0039b318 100644 --- a/libs/fuzzlib/fuzzer_helper.py +++ b/libs/fuzzlib/fuzzer_helper.py @@ -27,6 +27,8 @@ import pipes import traceback import time import copy +import shutil +from pprint import pprint from tools.colored import Colored from tools.templates import GN_ENTRY_TEMPLATE @@ -34,8 +36,6 @@ from tools.templates import PROJECT_GN_TEMPLATE from tools.templates import PROJECT_DEMO_TEMPLATE from tools.templates import PROJECT_HEADER_TEMPLATE from tools.templates import PROJECT_XML_TEMPLATE -import shutil -from pprint import pprint from tools.run_result import RunResult CURRENT_DIR = os.path.dirname(os.path.realpath(__file__)) diff --git a/libs/fuzzlib/tools/run_result.py b/libs/fuzzlib/tools/run_result.py index 5fb2b6edc683e9f0a27568eccde9384378da423f..8898e750cbe98998659f572b2b10269aa832a62f 100644 --- a/libs/fuzzlib/tools/run_result.py +++ b/libs/fuzzlib/tools/run_result.py @@ -83,8 +83,8 @@ class RunResult(): if __name__ == "__main__": - cmd_log = "" + CMD_LOG = "" res_obj = RunResult(0, "OK") - res_obj.analysis(cmd_log, "../../../out/") + res_obj.analysis(CMD_LOG, "../../../out/") print(res_obj.crash_info) diff --git a/src/core/build/pretreat_targets.py b/src/core/build/pretreat_targets.py index 7d30c9e13f36535c69eee352b617173dca10004d..b3c537c5fbe62a9592d864e9ad561e456320acfe 100644 --- a/src/core/build/pretreat_targets.py +++ b/src/core/build/pretreat_targets.py @@ -21,8 +21,8 @@ import sys import json import shutil -from core.constants import JsTestConst from xdevice import platform_logger +from core.constants import JsTestConst LOG = platform_logger("PretreatTargets") diff --git a/src/core/command/console.py b/src/core/command/console.py index a8b38225b68b649bed148d14b360e8c1eca836a1..87bbd962aa5f4f924ba4355f4a26498caa49fe7b 100755 --- a/src/core/command/console.py +++ b/src/core/command/console.py @@ -21,9 +21,10 @@ import sys import signal import platform -from core.constants import ToolCommandType from xdevice import platform_logger from xdevice import EnvironmentManager + +from core.constants import ToolCommandType from core.command.run import Run from core.command.gen import Gen from core.command.display import display_help_info diff --git a/src/core/command/run.py b/src/core/command/run.py index d89d6577e882c39367246e97ec0e78bd5f4ee0b4..f0798873102db338b6152d90f6d53088c73a8d7b 100755 --- a/src/core/command/run.py +++ b/src/core/command/run.py @@ -20,12 +20,12 @@ import time import os import sys -from core.constants import SchedulerType from xdevice import Plugin from xdevice import get_plugin from xdevice import platform_logger from xdevice import Scheduler from xdevice import DeviceTestType +from core.constants import SchedulerType from core.utils import get_build_output_path from core.utils import scan_support_product from core.utils import is_lite_product diff --git a/src/core/config/resource_manager.py b/src/core/config/resource_manager.py index 538b813dce5cf23e7c04717af23899d6f0d276ee..69c646367eb03a36d08713f46d96515003baf5fa 100755 --- a/src/core/config/resource_manager.py +++ b/src/core/config/resource_manager.py @@ -24,7 +24,6 @@ from xdevice import DeviceTestType from core.constants import ConfigFileConst LOG = platform_logger("ResourceManager") -DEFAULT_TIMEOUT = "300" ############################################################################## @@ -245,7 +244,7 @@ class ResourceManager(object): @classmethod def get_nodeattrib_data(cls, data_dic): - curr_timeout = DEFAULT_TIMEOUT + curr_timeout = "" if "nodeattrib" in data_dic.keys(): LOG.info("++++++++++++++nodeattrib+++++++++++++++") nodeattrib_list = data_dic["nodeattrib"] diff --git a/src/core/driver/drivers.py b/src/core/driver/drivers.py index ac93f2ba9963678ab1d965761c552c3283249246..93177842d572181b58d13e7f72bc5172b6cabdd1 100755 --- a/src/core/driver/drivers.py +++ b/src/core/driver/drivers.py @@ -54,6 +54,8 @@ LOG = platform_logger("Drivers") DEFAULT_TEST_PATH = "/%s/%s/" % ("data", "test") TIME_OUT = 900 * 1000 +JS_TIMEOUT = 10 +CYCLE_TIMES = 30 ############################################################################## @@ -353,7 +355,7 @@ class ResultManager(object): result_josn_file_path) result_file_path = result_josn_file_path else: - LOG.error("%s not exist", remote_result_file) + LOG.info("%s not exist", remote_result_file) return result_file_path @@ -481,12 +483,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(filename) + self._push_corpus_if_exist(suite_file) # push resource files resource_manager = ResourceManager() @@ -533,9 +536,9 @@ class CppTestDriver(IDriver): resource_dir, self.config.device) - def _push_corpus_if_exist(self, filename): + def _push_corpus_if_exist(self, suite_file): if "fuzztest" == self.config.testtype[0]: - corpus_path = os.path.join(get_fuzzer_path(filename), "corpus") + corpus_path = os.path.join(get_fuzzer_path(suite_file), os.path.join("corpus", "init")) self.config.device.push_file(corpus_path, os.path.join(self.config.target_test_path, "corpus")) @@ -544,6 +547,7 @@ class CppTestDriver(IDriver): testlevel, testtype, target_test_path, + suite_file, filename): if "benchmark" == testtype[0]: test_para = (" --benchmark_out_format=json" @@ -561,7 +565,7 @@ class CppTestDriver(IDriver): if "fuzztest" == testtype[0]: cfg_list = FuzzerConfigManager(os.path.join(get_fuzzer_path( - filename), "project.xml")).get_fuzzer_config("fuzztest") + suite_file), "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] + \ @@ -637,7 +641,7 @@ class JSUnitTestDriver(IDriver): with os.fdopen(hilog_open, "a") as hilog_file_pipe: self.config.device.start_catch_device_log(hilog_file_pipe) self._init_jsunit_test() - self._run_jsunit(suite_file) + self._run_jsunit(suite_file, hilog) hilog_file_pipe.flush() self.generate_console_output(hilog, request) finally: @@ -652,13 +656,13 @@ class JSUnitTestDriver(IDriver): self.config.device.execute_shell_command( "mount -o rw,remount,rw /") - - def _run_jsunit(self, suite_file): + def _run_jsunit(self, suite_file, device_log_file): filename = os.path.basename(suite_file) resource_manager = ResourceManager() resource_data_dic, resource_dir = \ resource_manager.get_resource_data_dic(suite_file) + timeout = ResourceManager.get_nodeattrib_data(resource_data_dic) resource_manager.process_preparer_data(resource_data_dic, resource_dir, self.config.device) @@ -667,7 +671,35 @@ class JSUnitTestDriver(IDriver): if main_result: self._execute_hapfile_jsunittest() - self._uninstall_hap(self.package_name) + try: + status = False + actiontime = JS_TIMEOUT + times = CYCLE_TIMES + if timeout: + actiontime = timeout + times = 1 + device_log_file_open = os.open(device_log_file, os.O_RDONLY, + stat.S_IWUSR | stat.S_IRUSR) + with os.fdopen(device_log_file_open, "r", encoding='utf-8') \ + as file_read_pipe: + for i in range(0, times): + if status: + break + else: + time.sleep(float(actiontime)) + start_time = int(time.time()) + while True: + data = file_read_pipe.readline() + if data.find("JSApp:") != -1 and data.find("[end] run suites end") != -1: + LOG.info("execute testcase successfully.") + status = True + break + if int(time.time()) - start_time > 5: + break + + finally: + _lock_screen(self.config.device) + self._uninstall_hap(self.package_name) else: self.result = result.get_test_results("Error: install hap failed") LOG.error("Error: install hap failed") @@ -705,7 +737,7 @@ class JSUnitTestDriver(IDriver): as file_read_pipe: while True: data = file_read_pipe.readline() - if not data or not data.strip(): + if not data: break # only filter JSApp log if data.find("JSApp:") != -1: @@ -723,7 +755,6 @@ class JSUnitTestDriver(IDriver): except (ExecuteTerminate, DeviceError) as exception: return_message = str(exception.args) - _lock_screen(self.config.device) return return_message def _install_hap(self, suite_file): @@ -752,7 +783,6 @@ class JSUnitTestDriver(IDriver): if "success" in str(result_value).lower(): LOG.info("execute %s's testcase success. result value=%s" % (self.package_name, result_value)) - time.sleep(30) else: LOG.info("execute %s's testcase failed. result value=%s" % (self.package_name, result_value)) diff --git a/src/core/testcase/testcase_manager.py b/src/core/testcase/testcase_manager.py index d0ac52af924604fa789f25c1dff2895ea3282e7c..dc1bd577866df0ee9ea78e01cef1412ea0b05b3b 100755 --- a/src/core/testcase/testcase_manager.py +++ b/src/core/testcase/testcase_manager.py @@ -18,9 +18,10 @@ import os import copy + +from xdevice import platform_logger from core.utils import get_file_list_by_postfix from core.config.config_manager import FilterConfigManager -from xdevice import platform_logger LOG = platform_logger("TestcaseManager") diff --git a/src/core/utils.py b/src/core/utils.py index 45d10b2ee3e7c809ddc73843525959631deb5ae0..fc0a58974ee962884e90903d848494a39edd44bc 100755 --- a/src/core/utils.py +++ b/src/core/utils.py @@ -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.lower()) + return fuzzer_path def is_lite_product(product_form, code_root_path): diff --git a/src/main/__init__.py b/src/main/__init__.py index d414ea5ceda3d5e6ef735cbf798592bf73c98851..81cae9cb7a987e10a92ec5570ad530372788ccea 100755 --- a/src/main/__init__.py +++ b/src/main/__init__.py @@ -16,8 +16,8 @@ # limitations under the License. # -from . import _init_global_config from core.command.console import Console +from . import _init_global_config __all__ = [ "Console", diff --git a/src/main/__main__.py b/src/main/__main__.py index 72a567ed64d0af2298772c6b5c5f0d69c26447cb..be624023f9c939085478a926f70d76c67adb7d76 100755 --- a/src/main/__main__.py +++ b/src/main/__main__.py @@ -17,8 +17,9 @@ # import sys -from main import Console + from xdevice import platform_logger +from main import Console LOG = platform_logger("main")