Pull Request已成功合入, 合并人@ascend-robot
(感谢 yangchen 的贡献)变更摘要
此 PR 为显存 OOM 分析功能新增了单元测试和冒烟测试覆盖,主要围绕 OOMDetailedAnalyzer 类进行验证。单元测试覆盖了分析器启用判断、防抖 dump 控制、近期分配记录查询(按时间戳降序)和 Top 内存分配查询(按大小降序),以及 oomTopK 参数对结果数量的控制。冒烟测试则通过命令行 --analysis=oom:K 拉起实际训练脚本触发 OOM,并验证生成的 dump CSV 中是否包含 OOM_DETAIL 事件的三种子类型(OOM_TRIGGER、OOM_RECENT_ALLOC、OOM_TOP_ALLOC)及其必要字段。
主要改动
-
新增
test_analysis/test_oom_detailed_analyzer.cpp单元测试:为OOMDetailedAnalyzer类添加 9 个测试用例,涵盖IsEnabled、ShouldDumpDetails(含 2 秒防抖窗口验证)、QueryRecentAllocs(验证按时间戳降序及 TopK 截断)、QueryTopAllocs(验证按内存大小降序)以及空记录边界场景。测试通过InjectHalRecord和InjectNpuRecord辅助方法注入 HAL 和 NPU 内存事件。 -
在
test/smoke/run_st.py中集成 OOM 冒烟测试套件:新增导入OOMTestSuite,定义oom_cmd命令行参数(含--analysis=oom:5),并将OOMTestSuite注册到测试套件列表中,超时时间设为 60 秒。 -
新增
test/smoke/src/test_suit/oom_test.py冒烟用例:定义OOMTestSuite和OOMTestCase,通过 pandas 读取 dump CSV,校验OOM_DETAIL事件存在且包含三种Event Type(OOM_TRIGGER、OOM_RECENT_ALLOC、OOM_TOP_ALLOC),并验证OOM_TRIGGER的Attr字段包含func和req_size。 -
新增
test/smoke/testfile/scripts/test_oom_smoke.py烟雾测试脚本:通过torch_npu执行 1 步训练产生 alloc/free 记录后,调用trigger_oom循环分配 1GB tensor 直至触发 NPU OOM,供msmemscope命令行工具拉起并采集 OOM dump 数据。


代码审查
I've completed my thorough review of all four changed files. Here is my final summary.
审查总结
| 优先级 | 数量 |
|---|---|
| P0 | 0 |
| P1 | 0 |
| P2 | 1 |
| P3 | 0 |
各文件审查结果:
-
test/analysis/test_oom_detailed_analyzer.cpp— 无问题。新增的 C++ 单元测试覆盖了IsEnabled、ShouldDumpDetails、QueryRecentAllocs、QueryTopAllocs、TopK 控制、空记录等场景,测试逻辑正确,与oom_detailed_analyzer.cpp的实现保持一致。#define private public/#include <gtest/internal/gtest-port.h>均为项目既有约定,不视为本次 diff 引入的问题。 -
test/smoke/run_st.py— 无问题。变更仅为新增OOMTestSuite导入、oom_cmd命令定义、以及将其加入test_suites列表,与现有测试套件的注册模式完全一致。 -
test/smoke/src/test_suit/oom_test.py— 发现 1 个 P2 问题:_verify_csv方法中pd.read_csv及后续列访问均未做异常处理,CSV 格式异常时会导致整个冒烟测试运行崩溃,跳过后续所有测试套件。 -
test/smoke/testfile/scripts/test_oom_smoke.py— 无问题。冒烟脚本结构清晰,路径计算正确,逻辑简洁。
整体风险评估:低风险。 唯一的 P2 问题是测试代码自身的健壮性不足(缺少异常处理),不影响生产代码。该变更可以合入,建议修复上述 P2 问题以提升测试稳定性。
| 类型 | 数量 |
|---|---|
| 🔴 阻塞 | 0 |
| 🟡 建议 | 1 |
💬 仅评论


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-Ascend/msmemscope | ✅ 毛晨, 王朝 (2/2) | ✅ 毛晨 (1/1) |
💡 Tip:
- Committer can comment
/approveor/lgtm- Commenting
/approveimplies both code review (lgtm) and intent to merge (approve)
CLA Signature Pass
mnhdxnh, thanks for your pull request. All authors of the commits have signed the CLA. 👍


The MR is merging by another one
If you want to solve this problem, you can click here to do it in the FAQs.


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


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


感谢您贡献的Pull Request!
在提交之前,请务必阅读 Contributing。
1. 修改描述
2. 功能验证
3. 代码检视