Merged
fix:【PR】: 修改 将 == 误写为 = 导致条件恒真 #6612
liu-luAdd on 4 days ago
fix:【PR】: 修改 将 == 误写为 = 导致条件恒真 #6612
Merged
liu-luAdd on 4 days ago
liu-lu
liu-luCollaborators
4 days ago

Pull Request

描述

修复 ST 测试桩 tests/ut/aicpu_sched/aicpu_schedule/st/testcase/c_stub.c 中 drvQueryProcessHostPid 函数将相等比较 == 误写为赋值 = 的缺陷。

原代码 if (pid = 123789) 中,非零常量赋值使条件恒为真,导致无论传入任何 pid(包括 0 或非法负值)都会将 *host_pid 设为 789123,无法区分预设 PID 与其他输入,依赖该桩的 ST 测试会获得错误的进程映射,影响相关分支的验证。

修正为 if (pid == 123789) 后,仅当 pid 恰为预设值 123789 时才写入 *host_pid = 789123,恢复条件比较语义。

变更类型

请选择本次引入的变更类型:

关联的Issue

https://gitcode.com/cann/runtime/issues/1434

如何测试

描述测试此变更的步骤和前提条件:

  1. 编译验证:重新编译 aicpu_schedule ST 测试,确认编译通过且无告警(原赋值条件会触发编译器括号类告警)
  2. Stub 行为验证:
    • 传入 pid = 123789,验证 *host_pid 被设为 789123(匹配分支命中)
    • 传入其他 pid(如 0、负值、普通进程号),验证 *host_pid 不被修改,可与其他输入正确区分(不匹配分支不命中)
  3. 回归验证:运行 host_cpu_driver_stub_test.cc 中 drvQueryProcessHostPid 相关 ST 用例,确认全部通过

核对清单

其他信息

  • 该问题仅影响 ST 测试桩行为,不涉及运行时产品代码
  • 仓库内其余 c_stub.c(ut / sim / aicpu_cust_schedule)中的 drvQueryProcessHostPid 均为直接返回 DRV_ERROR_NONE 的空实现,不受此问题影响,无需一并修改
  • 本 PR 无文档变更需求
likedislike
Pull Request has been successfully merged by CANN-robot.
(Thank you for liu-lu's contribution.)
liu-luliu-luCollaborators
4 days ago Added label: enhancement
liu-luliu-luCollaborators
4 days ago Created pull request, commit caae718b
liu-luliu-luCollaborators
4 days ago Associated issue: CANN开发者共建计划--runtime aicpu_schedule c_stub.c drvQueryProcessHostPid 将 == 误写为 = 导致条件恒真
atomgit-bot
atomgit-bot
4 days ago Comments:

变更摘要

本 PR 针对测试桩代码中的赋值/比较运算符误写问题进行修复:在 tests/ut/aicpu_sched/aicpu_schedule/st/testcase/c_stub.c 中,桩函数 drvQueryProcessHostPid 的条件判断原写作 if (pid = 123789),属于把 == 误写成 =,导致条件恒为真且同时覆盖了入参 pid;现改为 if (pid == 123789),使该桩函数仅在传入 pid 等于 123789 时才写入 *host_pid,恢复预期的判定语义。

主要改动

  • 修正条件判断运算符: 将 drvQueryProcessHostPid 中的 if (pid = 123789) 改为 if (pid == 123789),消除赋值误用造成的条件恒真。
  • 恢复桩函数行为语义: 修改后 *host_pid = 789123 的赋值仅在 pid 等于 123789 时执行,避免对 pid 入参的意外改写并符合调用方对返回 host_pid 的预期。
likedislike
Incorrect?
atomgit-bot
atomgit-bot
4 days ago Comments:

代码审查

审查结论

变更文件逐一确认

  • tests/ut/aicpu_sched/aicpu_schedule/st/testcase/c_stub.c:已审查(唯一变更行为 drvQueryProcessHostPid 中 if (pid = 123789) → if (pid == 123789))。修复本身正确:消除了“非零常量赋值导致条件恒真、任意 pid 都回填 *host_pid = 789123”的缺陷,与 Issue #1434 的预期一致;pid 为 int,与常量 123789 比较无符号/宽度问题,返回值 DRV_ERROR_NONE 语义未变;已核对 ST 中的调用方(host_cpu_driver_stub_test.cc:46 传 pid = 2343,仅断言返回值)与 UT 中通过 MOCKER 替换的 fake 实现,本次修复不会破坏既有用例断言。未发现安全、内存、错误码/ErrMsg 相关问题(本文件不涉及结构化错误上报)。

问题统计

  • P0:0
  • P1:0
  • P2:0
  • P3:1(修复后的条件真分支无用例覆盖,属可选测试改进项,已标注低置信度)

总体风险判断

本次变更是单行、方向明确且正确的缺陷修复,不影响产品代码路径,仅改善测试桩语义;整体风险极低。唯一遗留问题是修复后的分支缺乏用例验证及调用方输出指针未初始化,建议作为后续可选改进,不阻塞合入。

类型 数量
🔴 阻塞 0
🟡 建议 1

💬 仅评论


🧩 本次 Review 实际调用自定义 Skill:

likedislike
Incorrect?
CANN-robotCANN-robotCollaborators
4 days ago Added label: cann-cla/yes
CANN-robot
CANN-robotCollaborators
4 days ago 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
tests/ut/aicpu_sched ✅ ZhaiPeiChao, LiWei79 (2/2) ✅ ZhaiPeiChao (1/1)

💡 Tip:

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

CLA Signature Pass

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

likedislike
CANN-robotCANN-robotCollaborators
4 days ago Set wangtao43,zhangpengpeng8,yanmingxiang,LiWei79,ZhaiPeiChao,Reyn52166,ykl999,houyanbao,tingwood as approver
CANN-robotCANN-robotCollaborators
4 days ago Set LiWei79,ZhaiPeiChao as approver
liu-lu
liu-luCollaborators
4 days ago Comments:

compile

likedislike
liu-luliu-luCollaborators
4 days ago Pre merge succeeded (commit_id: 28654be50771ac5e21e59c1ca316932bbc477937)
liu-luliu-luCollaborators
4 days ago Modify description of pull request
atomgit-bot
atomgit-bot4 days agoStart code review1
tests/ut/aicpu_sched/aicpu_schedule/st/testcase/c_stub.c
@@ -216,3 +216,3 @@
216- if (pid = 123789) {
216+ if (pid == 123789) {
217217 *host_pid = 789123;
218218 }
atomgit-bot
atomgit-bot4 days agoComments:

🔵 Low Priority

变更行(c_stub.c:216)把恒真的 if (pid = 123789) 改为 if (pid == 123789),修复本身正确。但修复后该条件的真分支(第 217 行 *host_pid = 789123)在 ST 中不再被任何调用命中:本文件唯一的调用方 tests/ut/aicpu_sched/aicpu_schedule/st/testcase/host_cpu_driver_stub_test.cc:41-46(HostCpuDriverStubUt.drvQueryProcessHostPid)固定传入 int pid = 2343,且 chip_id/vfid/host_pid/cp_type 四个输出指针声明后未初始化即传入。后果:(1) 本次修复的关键分支(pid 匹配才回填 host_pid)没有任何用例验证,修复前后测试都只靠 EXPECT_EQ(ret, DRV_ERROR_NONE) 通过,无法发现该桩逻辑再次写错;(2) 由于输出指针未初始化,若后续有用例按预期传入 pid = 123789,第 217 行会向野指针写入,属于未定义行为。说明:这是可选的测试质量改进项,不是必须修复的缺陷(PR 主体修复正确)。

建议:在 ST 用例中补充/改写对 drvQueryProcessHostPid 的调用:把 host_cpu_driver_stub_test.cc 中的输出指针初始化为真实变量(如 unsigned int chipId = 0, vfId = 0, hostPid = 0, cpType = 0; 后传地址),并按 pid = 123789 与 pid != 123789 两组入参分别断言 *host_pid == 789123 与 *host_pid 保持原值,从而覆盖本次修复新增的条件分支,避免明文桩逻辑回归。

likedislike
Incorrect?
CANN-robot
CANN-robotCollaborators
4 days ago Comments:
🚀 CI 流水线已启动
📋 执行详情: 点击查看流水线
likedislike
CANN-robotCANN-robotCollaborators
4 days ago Added label: ci-pipeline-running
liu-luliu-luCollaborators
4 days ago Modify description of pull request
CANN-robotCANN-robotCollaborators
4 days ago Removed label: ci-pipeline-running
CANN-robotCANN-robotCollaborators
4 days ago Added label: ci-pipeline-passed
liu-luliu-luCollaborators
4 days ago Resolved final issue
liu-wei
liu-weiCollaborators
3 days ago Comments:

/lgtm
/approve

likedislike
DevLeev
DevLeevCollaborators
3 days ago Comments:

/lgtm

likedislike
ZhaiPeiChao
ZhaiPeiChaoCollaborators
3 days ago Comments:

/lgtm
/approve

likedislike
CANN-robot
CANN-robotCollaborators
3 days ago Comments:

The following users do not have permission to comment /lgtm or /approve on any module in this PR:
/approve: 刘伟
/lgtm: 刘伟

likedislike
CANN-robotCANN-robotCollaborators
3 days ago Added label: lgtmapproved
CANN-robotCANN-robotCollaborators
3 days ago Closed associated issue
CANN-robotCANN-robotCollaborators
3 days ago Merged pull request