Pull Request已成功合入, 合并人@CANN-robot
(感谢 chenqi317 的贡献)变更摘要
此 PR 主要围绕 Kernel UT(单元测试)构建与运行流程,新增了防卡死超时机制、快速模式(跳过符号化并优化编译)以及覆盖率条件化控制。通过 build.sh 新增 --ut_mode 和 --ut_timeout 选项,将相关参数透传至 CMake;CMake 中将原本硬编码的覆盖率选项和调试符号改为条件化控制;同时新增 run_kernel_ut.sh 脚本实现逐用例超时执行与结果汇总。
主要改动
-
新增
--ut_mode与--ut_timeout构建选项:在build.sh中新增两个 long option,--ut_mode支持debug(启用符号化、-g、-O0)和fast(禁用符号化、-g0、-O2)两种模式,--ut_timeout指定每用例超时秒数(默认 30),并透传为 CMake 变量ENABLE_UT_SYMBOLIZE、UT_CASE_TIMEOUT、UT_DEBUG_FLAG。 -
覆盖率选项条件化控制:在
cmake/intf_pub_llt_gccnative.cmake中,将四个接口目标(intf_llt_pub、intf_llt_pub_asan、intf_llt_pub_asan_cxx14、intf_llt_pub_asan_cxx17)中原本硬编码的--coverage、-fprofile-arcs、-ftest-coverage编译选项及gcov链接库统一改为$<$<BOOL:${ENABLE_COVERAGE}>:...>条件生成器表达式,同时移除了硬编码的-g调试标志。 -
UT 编译调试标志可配置化:在
cmake/ut.cmake的AddOpTestCase函数中,将 operator kernel 用例及其辅助源文件的编译选项从固定-g替换为${UT_DEBUG_FLAG},使调试信息级别可由build.sh的--ut_mode控制。 -
新增 Kernel UT 逐用例超时运行脚本:新增
tests/ut/op_kernel/scripts/run_kernel_ut.sh,通过timeout --foreground逐用例执行 gtest 测试,支持禁用 addr2line 符号化(fake addr2line 脚本)、ASAN 预加载、禁用 core dump,并输出 pass/fail/timeout 汇总结果。 -
移除 classify_rule.yaml 中的重复匹配规则:删除了
matmul@ops-nn和matmul-quant@ops-nn分类规则中重复的- ops/ops-nn/matmul/*/op_kernel/条目。


代码审查
审查总结
按文件逐一确认:
| 文件 | 审查结论 |
|---|---|
CMakeLists.txt |
发现问题 — P1: ENABLE_UT_SYMBOLIZE 的 ON/OFF vs TRUE/FALSE 不匹配 |
build.sh |
无问题 — ccache 配置新增和 ut_mode/ut_timeout 参数处理均正确 |
classify_rule.yaml |
无问题 — 移除 matmul op_kernel 排除规则是合法的 YAML 变更 |
cmake/intf_pub_llt_gccnative.cmake |
无问题 — coverage 标志条件化改造正确;尾随空格清理无害 |
cmake/ut.cmake |
无问题 — -g → ${UT_DEBUG_FLAG} 和 gcov 条件化均正确一致 |
tests/ut/op_kernel/CMakeLists.txt |
发现问题 — P2: ASAN_OPTIONS=detect_leaks=0 丢失 |
tests/ut/op_kernel/scripts/run_kernel_ut.sh |
发现问题 — P2: 缺少 set -e/-u;P3: bash -c 拼接潜在风险 |
按优先级统计:
- P0: 0
- P1: 1(ENABLE_UT_SYMBOLIZE 值不匹配 → fast 模式符号化无法关闭)
- P2: 2(ASAN_OPTIONS 丢失、脚本鲁棒性不足)
- P3: 1(bash -c 命令拼接,低风险可选改进)
整体风险判断:中等。 P1 问题导致 --ut_mode=fast 的核心目的之一(禁用符号化以加速/防卡死)在当前代码路径下无法生效,需要修复后才能达到 PR 描述的"快速模式"效果。P2 的 ASAN_OPTIONS 丢失可能在实际 ASAN 测试中产生噪音或误报。
| 类型 | 数量 |
|---|---|
| 🔴 阻塞 | 1 |
| 🟡 建议 | 2 |
⛔ 需要修改


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 |
|---|---|---|
| activation | ✅ 汤平川, 查建青, 范其瑞 (3/2) | ✅ 汤平川, 查建青 (2/1) |
| cmake | ✅ 商晓波, 汤平川, 范其瑞 (3/2) | ✅ 商晓波 (1/1) |
| foreach | ✅ 范其瑞, 汤平川, 查建青 (3/2) | ✅ 查建青, 汤平川 (2/1) |
| index | ✅ 汤平川, 范其瑞 (2/2) | ✅ 汤平川 (1/1) |
| loss | ✅ 汤平川, 范其瑞 (2/2) | ✅ 汤平川 (1/1) |
| norm | ✅ 汤平川, 查建青, 范其瑞 (3/2) | ✅ 汤平川, 查建青 (2/1) |
| repo-cann/ops-nn | ✅ 汤平川, 范其瑞 (2/2) | ✅ 汤平川 (1/1) |
| tests | ✅ 查建青, 范其瑞, 汤平川 (3/2) | ✅ 查建青 (1/1) |
💡 Tip:
- Committer can comment
/approveor/lgtm- Commenting
/approveimplies both code review (lgtm) and intent to merge (approve)
CLA Signature Pass
chenqi317, thanks for your pull request. All authors of the commits have signed the CLA. 👍


/lgtm
/approve


Pull Request 已合并或已关闭。
If you want to solve this problem, you can click here to do it in the FAQs.


描述
提交总结:kernel ut 增加防卡死超时、快速模式、覆盖率控制
修改背景:Kernel UT 存在单测卡死导致整套测试挂起、运行慢(addr2line 符号化耗时)、gcov 覆盖率始终链接带来不必要开销等问题。
修改方案:
run_kernel_ut.sh,按 case 逐个执行并用timeout限时(默认 120s,--ut_timeout可配),超时即标记失败并继续,避免单点卡死阻塞全流程。--ut_mode=fast/debug。fast 模式关闭符号化(注入 fake addr2line 跳过慢解析)、改用-g0 -O2,用于快速验证;debug 模式保留-g与符号化,用于开发调试。gcov的无条件链接改为$<$<BOOL:${ENABLE_COVERAGE}>:gcov>条件链接,仅在开启覆盖率时引入;关联的Issue
https://gitcode.com/cann/ops-nn/issues/4606
测试
通过kernel ut 测试,bash build.sh -u --opkernel --ut_mode=fast --ut_timeout=60
文档更新
类型标签
AI/Agent生成声明