diff --git a/README_zh.md b/README_zh.md index 7dae01a3ace4deda9c688fef1f389b7915b9f7a0..58ce3dc48d75397c018f211a63b9ea2da1a6b32a 100755 --- a/README_zh.md +++ b/README_zh.md @@ -1134,6 +1134,53 @@ reports/platform_log_xxxx_xx_xx_xx_xx_xx.log reports/latest ``` +### 覆盖率用户指导 +1. (可选执行)为了屏蔽非核心代码产生的冗余分支数据,可以在源码编译之前进入/test/testfwk/developer_test/localCoverage/restore_comment目录下执行: + + python3 build_before_generate.py + + 选择对应的部件,执行命令例如: + + run -tp partname + run -tp partname1 partname2 +2. 编译版本之前首先修改编译选项,涉及到自己子系统的build.gn文件cflags或者cflags_cc及idflags选项都需要加--coverage字段: + + idflags = [ "--coverage" ] + C: cflags = [ "--coverage" ] + C++: cflags_cc = [ "--coverage" ] + +**推荐:** 也可以参考窗口子系统的方式(推荐这种方式),参考链接:https://gitee.com/openharmony/window_window_manager/pulls/1274/files +3. 执行覆盖率需要安装以下依赖包: + + 1)安装lcov. + 2)安装dos2unix, 安装命令:apt install dos2unix. + +4. 远程映射设备,修改usr_config.xml中的ip号,设备映射方式查看上面介绍的远程端口映射, + +``` + + + + + + +``` +5. 执行 + + ./start.sh + + 命令例如下: + run -t UT -tp 部件名 -cov coverage + run -t UT -ss 子系统名 -cov coverage + run -t UT -ss 子系统名 -tp 部件名 -cov coverage + run -t UT MST ST -tp 部件名 -cov coverage + +> **注意:** 必须添加 -cov coverage 参数 + +6. 覆盖率报告路径 + +/test/testfwk/developer_test/localCoverage/codeCoverage/results/coverage/reports/cxx/html + ### 涉及仓 [test\_xdevice](https://gitee.com/openharmony/testfwk_xdevice) @@ -1144,7 +1191,7 @@ reports/latest | ---------- | ------------------------------------------------------------ | | 3.2.1.0 | 1、增加框架对接执行ACTS测试用例能力
2、增加ACTS多种颗粒度执行能力,如子系统、部件等 | | 3.2.2.0 | 1、增加测试任务统计能力,最多统计10个任务
2、增加按照指定测试任务ID执行测试任务能力
3、增加复测上次任务失败用例能力 | - +| 3.2.3.0 | 1、增加覆盖率执行
| diff --git a/localCoverage/codeCoverage/codeCoverage_gcov_lcov.py b/localCoverage/codeCoverage/codeCoverage_gcov_lcov.py index 588c420d41d445d46114d559a865e9b32e8a45ca..ed6ab11b92a75eb33fab87e784b0e1c8977bc5d7 100644 --- a/localCoverage/codeCoverage/codeCoverage_gcov_lcov.py +++ b/localCoverage/codeCoverage/codeCoverage_gcov_lcov.py @@ -57,10 +57,12 @@ def call(cmd_list, is_show_cmd=False, out=None, err=None): def execute_command(command, printflag=False): try: cmd_list = shlex.split(command) - with open("coverage.log", 'a') as fd: + coverage_log_path = os.path.join( + CODEPATH, "test/testfwk/developer_test/localCoverage", "coverage.log") + with open(coverage_log_path, 'a') as fd: call(cmd_list, printflag, fd, fd) - except IOError as err: - print("Error: Exception occur in open err") + except IOError: + print("Error: Exception occur in open err") def get_subsystem_config_info(): diff --git a/localCoverage/codeCoverage/mutilProcess_CodeCoverage.py b/localCoverage/codeCoverage/mutilProcess_CodeCoverage.py index e5dd3c3ea706f8994dad81a2604871bb687ebb4b..4ece28cf281340c968c2e47e469b82c22406de91 100644 --- a/localCoverage/codeCoverage/mutilProcess_CodeCoverage.py +++ b/localCoverage/codeCoverage/mutilProcess_CodeCoverage.py @@ -63,10 +63,12 @@ def call(cmd_list, is_show_cmd=False, out=None, err=None): def execute_command(command, printflag=False): try: cmd_list = shlex.split(command) - with open("coverage.log", 'a') as fd: + coverage_log_path = os.path.join( + CODEPATH, "test/testfwk/developer_test/localCoverage", "coverage.log") + with open(coverage_log_path, 'a') as fd: call(cmd_list, printflag, fd, fd) - except IOError as err: - print("Error: Exception occur in open: %s", err.message) + except IOError: + print("Error: Exception occur in open error") def get_subsystem_config_info(): diff --git a/localCoverage/coverage_tools.py b/localCoverage/coverage_tools.py index 84b8e723a9bc9c9f7c35aa224b9f385101f2ece9..ad036c7fa528600970d0c0c5f18c2b7bf0944da6 100644 --- a/localCoverage/coverage_tools.py +++ b/localCoverage/coverage_tools.py @@ -117,10 +117,11 @@ def get_subsystem_name(test_part_list, product_name): def generate_product_name(root_path): - # 获取产品形态 - out_path = os.path.join(root_path, "out") - _, gcno_path = subprocess.getstatusoutput("find %s -name '*.gcno' | head -n 1" % out_path) - product_name = gcno_path.split(out_path)[1].strip("/").split("/")[0] + # 获取输出路径 + ohos_config_path = os.path.join(root_path, "ohos_config.json") + with open(ohos_config_path, 'r') as json_file: + json_info = json.load(json_file) + product_name = json_info.get("out_path").split("out")[1].strip("/") return product_name @@ -176,4 +177,4 @@ if __name__ == '__main__': subprocess.run("python3 %s" % restore_source_code_path, shell=True) print(r"See the code coverage report in: " - r"\test\testfwk\developer_test\localCoverage\codeCoverage\results\coverage\reports\cxx\html") + r"/test/testfwk/developer_test/localCoverage/codeCoverage/results/coverage/reports/cxx/html") diff --git a/src/core/driver/drivers.py b/src/core/driver/drivers.py index 0809239ed5690a13ceaf393a6d56377e44cb7082..723c856e65a885e05346dea4acf0472b83632b14 100644 --- a/src/core/driver/drivers.py +++ b/src/core/driver/drivers.py @@ -549,8 +549,11 @@ class CppTestDriver(IDriver): if coverage_outpath: strip_num = len(coverage_outpath.strip("/").split("/")) else: - root_path = (sys.framework_root_dir.split("test/testfwk/developer_test")[0]) - strip_num = len(root_path.strip("/").split("/")) + 2 + ohos_config_path = os.path.join(sys.source_code_root_path, "ohos_config.json") + with open(ohos_config_path, 'r') as json_file: + json_info = json.load(json_file) + out_path = json_info.get("out_path") + strip_num = len(out_path.strip("/").split("/")) if "fuzztest" == self.config.testtype[0]: self._push_corpus_cov_if_exist(suite_file) command = f"cd {self.config.target_test_path}; tar zxf {filename}_corpus.tar.gz; \ diff --git a/src/core/utils.py b/src/core/utils.py index da732265405932dd0af7819d008d92cd3aaad2cc..7be7853f6a09a49e3a42134f46a328c7b66d7f1d 100755 --- a/src/core/utils.py +++ b/src/core/utils.py @@ -126,6 +126,15 @@ def scan_support_product(): return productform_list +def get_output_path(): + # 获取输出路径 + ohos_config_path = os.path.join(sys.source_code_root_path, "ohos_config.json") + with open(ohos_config_path, 'r') as json_file: + json_info = json.load(json_file) + out_name = json_info.get("out_path").split("out")[1].strip("/") + return out_name + + def parse_device_name(product_form): device_json_file = os.path.join(sys.source_code_root_path, "productdefine", "common", "products", @@ -139,10 +148,7 @@ def parse_device_name(product_form): return device_name = json_info.get('product_device') if not device_name: - if product_form.startswith("rk"): - device_name = product_form - else: - device_name = "baltimore" + device_name = get_output_path() return device_name