Merged
fix(build): Flush gcov data for pytest-forked subprocess coverage #6148
chengding888Add on Sep 10
fix(build): Flush gcov data for pytest-forked subprocess coverage #6148
Merged
Merged fromchengding888/pyptomasterintocann/pyptomaster
Pull Request has been successfully merged by CANN-robot.
(Thank you for chengding888's contribution.)Sep 10 Created pull request, commit 9d6519bb
atomgit-bot
Sep 10 Comments:
Sep 10 Comments:
变更摘要
该 PR 旨在修复 pytest-forked 子进程模式下 gcov 覆盖率数据无法落盘的问题:--forked 模式下子进程通过 os._exit() 退出,会跳过 atexit,导致 gcov 的 __gcov_exit 不被调用、.gcda 文件不写入。改动通过在构建期导出 __gcov_dump 符号、在测试环境注入 PYPTO_GCOV_FLUSH 开关,并在 UT 的 pytest_runtest_teardown 钩子中手动调用 __gcov_dump() 将内存中的覆盖率计数器刷写为 .gcda 文件。
主要改动
- 构建脚本注入 gcov flush 开关:
build_ci.py的BuildCtrl在构建启用 gcov(self.build.gcov)时,向测试进程环境变量写入PYPTO_GCOV_FLUSH=1,作为子进程手动 flush 覆盖率数据的开关。 - 链接选项导出
__gcov_dump符号:cmake/intf.cmake在启用ENABLE_GCOV且使用 GNU 编译器时,为tile_fwk_intf_pub_base增加--export-dynamic,-u,__gcov_dump等链接选项,导出__gcov_dump符号供测试子进程调用。 - 新增 UT conftest 实现手动 flush:新增
python/tests/ut/conftest.py,在pytest_runtest_teardown中通过ctypes.CDLL(None)解析并调用__gcov_dump();仅当环境变量PYPTO_GCOV_FLUSH存在时才执行,从而在os._exit()前补齐 gcov 覆盖率数据写入。


Incorrect?
atomgit-bot
Sep 10 Comments:
Sep 10 Comments:
Sep 10 Added label: cann-cla/yes
CANN-robot
Sep 10 Comments:
Sep 10 Comments:
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.
You can self-configure the PR merge rules for this repository. For more details, please refer to Here.
For more, you also can visit HICANN.
PR Approval Progress
✅ Congratulations! All modules have met the lgtm and approve requirements.
Module Approval Details
| module | lgtm status | approve status |
|---|---|---|
| build_ci.py | ✅ 尹杰, lululu40888 (2/2) | ✅ 尹杰 (1/1) |
| cmake | ✅ lululu40888, 尹杰 (2/2) | ✅ 尹杰 (1/1) |
| repo-cann/pypto | ✅ tsungl4, 尹杰, lululu40888 (3/2) | ✅ tsungl4, 尹杰 (2/1) |
| tools/scripts | ✅ tsungl4, 尹杰, lululu40888 (3/2) | ✅ tsungl4, 尹杰 (2/1) |
💡 Tip:
- Committer can comment
/approveor/lgtm- Commenting
/approveimplies both code review (lgtm) and intent to merge (approve)
CLA Signature Pass
chengding888, thanks for your pull request. All authors of the commits have signed the CLA. 👍


91 messages are collapsed here。 See more
huanglu
Sep 14 Comments:
Sep 14 Comments:
/lgtm


lidongsheng
Sep 14 Comments:
Sep 14 Comments:
/approve


Jie Yin
Sep 15 Comments:
Sep 15 Comments:
/approve


Sep 15 Added label: lgtmapproved
Sep 15 Merged pull request
背景
Python UT 通过
--forked(pytest-forked)并行执行用例,子进程以os._exit()退出,会跳过 atexit 钩子,导致 gcov 的__gcov_exit不被调用、.gcda覆盖率数据不落盘。因此--gcov无法统计到由 Python UT 触发的 C++ 覆盖率(issue #2705)。解决方案
python/tests/ut/conftest.py:新增pytest_runtest_teardown钩子,当环境变量PYPTO_GCOV_FLUSH=1时手动调用__gcov_dump(),把内存中的计数器写入.gcda;并补充duration_estimate装饰器。build_ci.py:--gcov时注入PYPTO_GCOV_FLUSH=1。cmake/intf.cmake:gcov 模式追加链接选项-Wl,--export-dynamic,-u,__gcov_dump,--whole-archive,-lgcov,--no-whole-archive。仅加-u,__gcov_dump时_gcov_dump.o不会被lgcov.a拉入,__gcov_dump保持未定义,ctypes.CDLL(None)找不到该符号,必须用--whole-archive强制拉入。cmake/scripts/gen_coverage.py:lcov >= 2.0 时追加--ignore-errors inconsistent,将 lcov 2.3.1 对pybind11.cpp的mismatched end line由 ERROR 降级为 WARNING,避免覆盖率生成失败。tools/scripts/pre_commit_check.sh:--py_cov→--gcov)、clang 失败退出码、GTEST_FILTER保存/恢复、覆盖率标签等;gen_coverage.py --increment与 CI 的get_ai_inc_cov.py(addlcov) 是两套独立实现,增量覆盖率无法保证与 CI 一致,门禁统一由 CI 兜底。验证
bash tools/scripts/pre_commit_check.sh --full全部通过(gnu / clang+ASan / Python / costmodel 仿真,耗时约 4779s)。.gcda)可正常落盘并被--gcov统计。Related Issue: #2705