已合并
test: add_example kernel UT 补输入初始化与输出校验(修复 #27) #91
test: add_example kernel UT 补输入初始化与输出校验(修复 #27) #91
已合并
不喜欢雨天ༀ创建于 29 天前
不喜欢雨天ༀ
29 天前

Problem

examples/add_example/tests/ut/op_kernel/test_add_example.cpp 的 test_case_0 零断言(EXPECT_*/ASSERT_* 数量为 0)且输入 x/y 分配后未初始化——ICPU_RUN_KF 之后直接释放内存,kernel 计算错误(甚至写出垃圾)也不会导致用例失败(对应 #27)。

Root cause

原实现只演示了 kernel 运行机制,缺少输入构造与结果校验。

Fix

  • ICPU_RUN_KF 前将 x/y 填入已知值:x[i]=i, y[i]=2i
  • 运行后逐元素校验 z[i] == x[i] + y[i](float32 加法位精确,位级比较;期望值 3i 在 fp32 下精确可表示)
  • 顺带将魔数 3244*4 收敛为 totalLength 常量复用

Verification

  • 新增代码 gtest 片段本地语法编译通过
  • 与同仓其余测试层对齐:test_add_example_tiling.cpp 校验 tiling 输出、fast_kernel_launch_example/tests/add/test_add.py 校验计算结果,本修复补齐 kernel UT 的校验缺口
  • 不改动 kernel 与存量格式(仅新增行符合 clang-format)

仅改测试文件,不影响 kernel 行为。

likedislike
Pull Request已成功合入, 合并人@CANN-robot
(感谢 不喜欢雨天ༀ 的贡献)
不喜欢雨天ༀ不喜欢雨天ༀ
29 天前 创建了 pull request,commit af62c8fc
不喜欢雨天ༀ不喜欢雨天ༀ
29 天前 关联了issue:[Test] add_example kernel UT 零断言且输入未初始化,恒真通过
atomgit-bot
atomgit-bot
29 天前 评论:

变更摘要

本 PR 为 examples/add_example/tests/ut/op_kernel/test_add_example.cpp 中的 add_example_test::test_case_0 补齐输入构造与输出校验,修复 #27(该用例零断言且输入未初始化的问题)。改动在 ICPU_RUN_KF 前将输入 x、y 填入已知值(x[i]=i、y[i]=2i),运行后逐元素校验 z[i] == x[i] + y[i](float32 加法位精确,期望值 3i 可精确表示),并顺带将魔数 32 * 4 * 4 * 4 收敛为 totalLength 常量复用。仅改动测试文件,不影响 kernel 行为。

主要改动

  • 输入初始化:在 ICPU_RUN_KF 前将 x/y 缓冲区转换为 float* 并填入已知值 xFloat[i] = i、yFloat[i] = 2i,使 kernel 输出具备可校验的期望基准
  • 输出校验:kernel 运行后新增逐元素断言 EXPECT_EQ(zFloat[i], xFloat[i] + yFloat[i]),并带索引信息的失败提示消息,使计算错误会触发用例失败
  • 常量收敛:新增 constexpr size_t totalLength = 32UL * 4UL * 4UL * 4UL,替代三处重复的魔数 32 * 4 * 4 * 4 字节尺寸计算,并复用于 tilingDatafromBin->totalLength 赋值
likedislike
不准确?
atomgit-bot
atomgit-bot
29 天前 评论:

代码审查

✅ 未发现问题

likedislike
不准确?
不喜欢雨天ༀ
不喜欢雨天ༀ
29 天前 评论:

compile

likedislike
CANN-robotCANN-robot成员
29 天前 添加了label:cann-cla/yes
CANN-robot
CANN-robot成员
29 天前 评论:

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
repo-cann/ops-ras ✅ 陈兴宇, yue-ma (2/2) ✅ yue-ma, 陈兴宇 (2/1)

💡 Tip:

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

CLA Signature Pass

2403_87936996, thanks for your pull request. All authors of the commits have signed the CLA. 👍

likedislike
CANN-robotCANN-robot成员
29 天前 添加了label:ci-pipeline-running
CANN-robot
CANN-robot成员
29 天前 评论:

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

任务名称状态日志下载链接
PreSmoke_ATK_Test_A2 ✅ SUCCESS >>>>>

[2026-09-03 13:10:43]    CI执行结束

likedislike
CANN-robot
CANN-robot成员
29 天前 评论:

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

任务名称状态日志下载链接
Compile_Ascend_X86 ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_X86_mobile_station ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_ARM ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_single ✅ SUCCESS >>>>> >>>>>
pre_comment ✅ SUCCESS >>>>>
Compile_Ascend_X86_ubuntu24 ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_X86_mobile_station_ubuntu24 ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_ARM_ubuntu24 ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_single_ubuntu24 ✅ SUCCESS >>>>> >>>>>
UT_Test_ophost ✅ SUCCESS
UT_Test_opapi ✅ SUCCESS
API_Check ✅ SUCCESS >>>>>

[2026-09-03 13:12:59]    CI执行结束

likedislike
CANN-robotCANN-robot成员
29 天前 添加了label:api-check-pass
CANN-robotCANN-robot成员
29 天前 删除了label:api-check-pass
CANN-robot
CANN-robot成员
29 天前 评论:

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

任务名称状态日志下载链接
codecheck ✅ SUCCESS >>>>>
SCA ✅ SUCCESS >>>>>
antipoison ✅ SUCCESS >>>>>
codecheck_Pr ✅ SUCCESS
codecheck_codestyle ✅ SUCCESS >>>>>
codecheck_precommit ⚠️ WARNING >>>>> >>>>>

[2026-09-03 13:14:45]    CI执行结束

likedislike
CANN-robotCANN-robot成员
29 天前 删除了label:ci-pipeline-running
CANN-robotCANN-robot成员
29 天前 添加了label:ci-pipeline-passed
不喜欢雨天ༀ
不喜欢雨天ༀ
29 天前 评论:

/compile 已全绿(6 个任务 ✅)。修复要点:test_case_0 原为零断言且输入未初始化,现补齐已知值输入(x=i, y=2i)与逐元素位级校验(z[i]==x[i]+y[i],fp32 位精确)。@LiuZonggu 恳请检视合入,谢谢!(对应 issue #27)

likedislike
CANN-robotCANN-robot成员
29 天前 删除了label:ci-pipeline-passed
CANN-robotCANN-robot成员
29 天前 添加了label:ci-pipeline-running
CANN-robotCANN-robot成员
29 天前 删除了label:ci-pipeline-running
CANN-robotCANN-robot成员
29 天前 添加了label:ci-pipeline-failed
不喜欢雨天ༀ
不喜欢雨天ༀ
28 天前 评论:

compile

likedislike
CANN-robotCANN-robot成员
28 天前 删除了label:ci-pipeline-failed
CANN-robotCANN-robot成员
28 天前 添加了label:ci-pipeline-running
CANN-robot
CANN-robot成员
28 天前 评论:

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

任务名称状态日志下载链接
PreSmoke_ATK_Test_A2 ✅ SUCCESS >>>>>

[2026-09-04 09:46:56]    CI执行结束

likedislike
CANN-robot
CANN-robot成员
28 天前 评论:

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

任务名称状态日志下载链接
Compile_Ascend_X86 ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_X86_mobile_station ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_ARM ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_single ✅ SUCCESS >>>>> >>>>>
pre_comment ✅ SUCCESS >>>>>
Compile_Ascend_X86_ubuntu24 ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_X86_mobile_station_ubuntu24 ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_ARM_ubuntu24 ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_single_ubuntu24 ✅ SUCCESS >>>>> >>>>>
UT_Test_ophost ✅ SUCCESS
UT_Test_opapi ✅ SUCCESS
API_Check ✅ SUCCESS >>>>>

[2026-09-04 09:59:28]    CI执行结束

likedislike
CANN-robot
CANN-robot成员
28 天前 评论:

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

任务名称状态日志下载链接
codecheck ✅ SUCCESS >>>>>
SCA ✅ SUCCESS >>>>>
antipoison ✅ SUCCESS >>>>>
codecheck_Pr ✅ SUCCESS
codecheck_codestyle ✅ SUCCESS >>>>>
codecheck_precommit ⚠️ WARNING >>>>> >>>>>

[2026-09-04 09:55:08]    CI执行结束

likedislike
CANN-robotCANN-robot成员
28 天前 添加了label:api-check-pass
CANN-robotCANN-robot成员
28 天前 删除了label:ci-pipeline-running
CANN-robotCANN-robot成员
28 天前 添加了label:ci-pipeline-passed
yue-ma成员
20 天前 评论:

/lgtm
/approve

likedislike
CANN-robotCANN-robot成员
20 天前 添加了label:approved
chenxingyu18成员
15 天前 评论:

/lgtm
/approve

likedislike
CANN-robotCANN-robot成员
15 天前 添加了label:lgtm
CANN-robotCANN-robot成员
15 天前 关闭了关联的issue
CANN-robotCANN-robot成员
15 天前 合入了pull request