已合并
fix(cov): 加强cpp覆盖率脚本以适配lcov版本差异并容忍空数据 #966
liu-wei创建于 6月10日
fix(cov): 加强cpp覆盖率脚本以适配lcov版本差异并容忍空数据 #966
已合并
liu-wei创建于 6月10日
liu-wei
liu-wei成员
6月10日

描述

scripts/util/generate_cpp_cov.sh 在以下场景会出现问题,本 PR 集中修复:

  1. lcov 1.x / 2.x 错误项不兼容:旧脚本用 [[ "${version}" =~ ^2\. ]] 正则判断版本号,
    对未来 lcov 3.x / 1.10 等版本不友好;--ignore-errors 参数在 generate_coverage
    filter_coveragegenerate_html 三处分别硬编码,重复且不一致。
  2. 空数据场景下 genhtml 报错:当过滤后的覆盖率文件为空时 genhtml 仍会被调用,
    触发 ERROR: no records found 错误,导致 CMake 目标失败。
  3. clean build 场景下整条流水线崩溃:源目录中无任何 .gcda 文件时
    (如未执行 UT 编译或跳过覆盖率),脚本仍会尝试 lcov --capture 并失败。

改动要点:

  • 新增 version_ge 辅助函数,基于 major/minor 数值做版本比较,
    替代临时拼凑的 =~ ^2\. 正则。
  • 拆分 --ignore-errors 构造逻辑为两个函数:
    • build_ignore_errors_opt:用于 lcov --capture
    • build_ignore_errors_remove_opt:用于 lcov --remove / lcov --extract
    • 两份函数分别针对 lcov 1.x 与 2.x 选择合适的错误忽略项。
  • generate_html 增加空文件保护:过滤后的 coverage.info 为空时仅记录日志,
    不再调用 genhtml
  • 入口新增 find ... -name "*.gcda" 守卫:源目录无任何 .gcda 数据时
    直接 logging "No coverage data found"不再 exit 1,让 CMake 流程能继续。

行为变更(向上兼容):

  • 入口参数不变:DIR COV_FILE OUT_PATH [UT_TYPE] [OP_NAMES],向后兼容。
  • 旧版无数据时 exit 1,新版 graceful 退出。如果有上游流水线依赖旧退出码,
    需要相应调整。

关联的Issue

关联 Issue: #514(https://gitcode.com/cann/ops-cv/issues/514)

测试

文档更新

  • 入口 Usage 文案保持不变,不涉及其他文档。

类型标签

likedislike
Pull Request已成功合入, 合并人@CANN-robot
(感谢 liu-wei 的贡献)
liu-weiliu-wei成员
6月10日 创建了 pull request,commit 798d27cc
CANN-robotCANN-robot成员
6月10日 添加了label:cann-cla/yes
CANN-robot
CANN-robot成员
6月10日 评论:

Thanks for your pull-request.
The full list of commands accepted by me can be found at here
You can get sig-info at here


PR Approval Progress

Congratulations! All modules have met the lgtm and approve requirements.

Module Approval Details

module lgtm status approve status
repo-cann/ops-cv 王林木, 张磊 (2/2) 王林木, 张磊 (2/1)

💡 Tip:

  • Committer can comment /approve or /lgtm
  • Commenting /approve implies both code review (lgtm) and intent to merge (approve)

CLA Signature Pass

liu-wei, thanks for your pull request. All authors of the commits have signed the CLA. 👍

likedislike
liu-weiliu-wei成员
6月10日 修改了pull request 的描述
liu-wei
liu-wei成员
6月10日 评论:

compile

likedislike
liu-weiliu-wei成员
6月10日 update merge request[project id: 7657293, iid: 966, commit_id: e0b17d25aaaefeaf62d198a1b35d96ff11d78cdf] virtual merging success
CANN-robotCANN-robot成员
6月10日 添加了label:ci-pipeline-running
CANN-robot
CANN-robot成员
6月10日 评论:

流水线任务触发成功
任务链接 [4ce597e191844a1b83303c28e5571a81][流水线指导]

任务名称状态日志下载链接
Compile_Ascend_X86 ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_X86_mobile_station ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_ARM ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_X86_experimental ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_ARM_experimental ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_X86_A5 ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_ARM_A5 ✅ SUCCESS >>>>> >>>>>
pre_comment ✅ SUCCESS >>>>>
Compile_Pre ✅ SUCCESS >>>>>
Compile_Ascend_X86_ubuntu24 ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_X86_mobile_station_ubuntu24 ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_X86_experimental_ubuntu24 ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_X86_A5_ubuntu24 ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_ARM_ubuntu24 ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_ARM_experimental_ubuntu24 ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_ARM_A5_ubuntu24 ✅ SUCCESS >>>>> >>>>>
Compile_X86_monitor_910b ✅ SUCCESS >>>>> >>>>>
Compile_X86_monitor_910c ✅ SUCCESS >>>>> >>>>>
Compile_X86_monitor_950 ✅ SUCCESS >>>>> >>>>>
UT_Test ✅ SUCCESS
PreSmoke_A900 ✅ SUCCESS >>>>>
API_Check ✅ SUCCESS >>>>>
PreSmoke_ATK_Test_A2 ✅ SUCCESS >>>>>

[2026-06-10 14:19:26]    CI执行结束

likedislike
CANN-robot
CANN-robot成员
6月10日 评论:

流水线任务触发成功
任务链接 [a7e550d670f54217b6ff370feaa19254][流水线指导]

任务名称状态日志下载链接
codecheck ✅ SUCCESS >>>>>
SCA ✅ SUCCESS >>>>>
antipoison ✅ SUCCESS >>>>>
codecheck_checkpr ✅ SUCCESS
StaticCheck_codespell_check ✅ SUCCESS
StaticCheck_link_validity_check ✅ SUCCESS
StaticCheck_resource_existence_check ✅ SUCCESS
StaticCheck_tag_closed_check ✅ SUCCESS
StaticCheck_markdownlint ✅ SUCCESS
codecheck_codestyle ✅ SUCCESS >>>>>
codecheck_precommit ✅ SUCCESS >>>>> >>>>>

[2026-06-10 14:17:29]    CI执行结束

likedislike
CANN-robotCANN-robot成员
6月10日 添加了label:api-check-pass
CANN-robotCANN-robot成员
6月10日 删除了label:ci-pipeline-running
CANN-robotCANN-robot成员
6月10日 添加了label:ci-pipeline-passed
liu-weiliu-wei成员
6月11日 修改了pull request 的描述
llimwang成员
6月11日 评论:

/approve

likedislike
CANN-robotCANN-robot成员
6月11日 添加了label:approved
zl_hw成员
6月11日 评论:

/lgtm
/approve

likedislike
CANN-robotCANN-robot成员
6月11日 添加了label:lgtm
CANN-robotCANN-robot成员
6月11日 关闭了关联的issue
CANN-robotCANN-robot成员
6月11日 合入了pull request