| @@ -119,6 +119,13 @@ app为必选,相关参数说明请参见[app参数说明](general_collect_comm | |||
| 119 | - Ascend 950PR&950DT系列产品:不支持 | 119 | - Ascend 950PR&950DT系列产品:不支持 |
| 120 | <!-- end id12 --> | 120 | <!-- end id12 --> |
| 121 | 121 | ||
| 122 | +- Custom:支持自定义需要采集的寄存器,例如:--aic-metrics=Custom:0x49,0x8,0x15,0x1b,0x64,0x10。Custom字段表示自定义类型,配置为具体的寄存器值,范围[0x1, 0x7FFFFFFF]。并非所有的可取值都有对应的PMU寄存器,若配置的值无对应PMU寄存器,则采集结果可能为0。配置的寄存器数最多不能超过8个,寄存器通过“,”区分开。寄存器的值支持十六进制或十进制。 | ||
| 123 | + | ||
| 124 | + <!-- npu="950" id36 --> | ||
| 125 | + > [!NOTE]说明 | ||
| 126 | + >Ascend 950PR&950DT系列产品配置的寄存器数最多不能超过10个,取值范围是[0x0, 0x7FFFFFFF]。 | ||
| 127 | + <!-- end id36 --> | ||
| 128 | + | ||
| 122 | 默认值: | 129 | 默认值: |
| 123 | 130 | ||
| 124 | <!-- npu="310b" id13 --> | 131 | <!-- npu="310b" id13 --> |
| @@ -142,8 +149,6 @@ app为必选,相关参数说明请参见[app参数说明](general_collect_comm | |||
| 142 | 149 | ||
| 143 | <!-- @ref: oam-tools/res/docs/zh/profiling/msprof_cmd/ai_runtime_profile_data_res.md#id00002 --> | 150 | <!-- @ref: oam-tools/res/docs/zh/profiling/msprof_cmd/ai_runtime_profile_data_res.md#id00002 --> |
| 144 | 151 | ||
| 145 | -支持自定义需要采集的寄存器,例如:--aic-metrics=Custom:0x49,0x8,0x15,0x1b,0x64,0x10。Custom字段表示自定义类型,配置为具体的寄存器值,范围\[0x1, 0x7FFFFFFF\]。并非所有的可取值都有对应的PMU寄存器,若配置的值无对应PMU寄存器,则采集结果可能为0。配置的寄存器数最多不能超过8个,寄存器通过“,”区分开。寄存器的值支持十六进制或十进制。 | ||
| 146 | - | ||
| 147 | <!-- @ref: oam-tools/res/docs/zh/profiling/msprof_cmd/ai_runtime_profile_data_res.md#id00003 --> | 152 | <!-- @ref: oam-tools/res/docs/zh/profiling/msprof_cmd/ai_runtime_profile_data_res.md#id00003 --> |
| 148 | 153 | ||
| 149 | ### sys-hardware-mem | 154 | ### sys-hardware-mem |
| @@ -108,6 +108,13 @@ msprof [options] <app> | |||
| 108 | - Ascend 950PR&950DT系列产品:不支持 | 108 | - Ascend 950PR&950DT系列产品:不支持 |
| 109 | <!-- end id14 --> | 109 | <!-- end id14 --> |
| 110 | 110 | ||
| 111 | +- Custom:支持自定义需要采集的寄存器,例如:--aic-metrics=Custom:0x49,0x8,0x15,0x1b,0x64,0x10。Custom字段表示自定义类型,配置为具体的寄存器值,范围[0x1, 0x7FFFFFFF]。并非所有的可取值都有对应的PMU寄存器,若配置的值无对应PMU寄存器,则采集结果可能为0。配置的寄存器数最多不能超过8个,寄存器通过“,”区分开。寄存器的值支持十六进制或十进制。 | ||
| 112 | + | ||
| 113 | + <!-- npu="950" id66 --> | ||
| 114 | + > [!NOTE]说明 | ||
| 115 | + >Ascend 950PR&950DT系列产品配置的寄存器数最多不能超过10个,取值范围是[0x0, 0x7FFFFFFF]。 | ||
| 116 | + <!-- end id66 --> | ||
| 117 | + | ||
| 111 | 默认值: | 118 | 默认值: |
| 112 | 119 | ||
| 113 | <!-- npu="310b" id15 --> | 120 | <!-- npu="310b" id15 --> |
| @@ -131,8 +138,6 @@ msprof [options] <app> | |||
| 131 | 138 | ||
| 132 | <!-- @ref: oam-tools/res/docs/zh/profiling/msprof_cmd/processorai_accelerator_system_data_res.md#id00002 --> | 139 | <!-- @ref: oam-tools/res/docs/zh/profiling/msprof_cmd/processorai_accelerator_system_data_res.md#id00002 --> |
| 133 | 140 | ||
| 134 | -支持自定义需要采集的寄存器,例如:--aic-metrics=Custom:0x49,0x8,0x15,0x1b,0x64,0x10。Custom字段表示自定义类型,配置为具体的寄存器值,范围\[0x1, 0x7FFFFFFF\]。并非所有的可取值都有对应的PMU寄存器,若配置的值无对应PMU寄存器,则采集结果可能为0。配置的寄存器数最多不能超过8个,寄存器通过“,”区分开。寄存器的值支持十六进制或十进制。 | ||
| 135 | - | ||
| 136 | <!-- @ref: oam-tools/res/docs/zh/profiling/msprof_cmd/processorai_accelerator_system_data_res.md#id00003 --> | 141 | <!-- @ref: oam-tools/res/docs/zh/profiling/msprof_cmd/processorai_accelerator_system_data_res.md#id00003 --> |
| 137 | 142 | ||
| 138 | ### sys-hardware-mem | 143 | ### sys-hardware-mem |
| @@ -155,6 +155,13 @@ AI Core性能指标采集项。task_time或task_trace配置为on、l1或l2时, | |||
| 155 | - Ascend 950PR&950DT系列产品:不支持 | 155 | - Ascend 950PR&950DT系列产品:不支持 |
| 156 | <!-- end id12 --> | 156 | <!-- end id12 --> |
| 157 | 157 | ||
| 158 | +- Custom:支持自定义需要采集的寄存器,例如:"aic_metrics":"Custom:0x49,0x8,0x15,0x1b,0x64,0x10"。Custom字段表示自定义类型,配置为具体的寄存器值,范围[0x1, 0x7FFFFFFF]。并非所有的可取值都有对应的PMU寄存器,若配置的值无对应PMU寄存器,则采集结果可能为0。配置的寄存器数最多不能超过8个,寄存器通过“,”区分开。寄存器的值支持十六进制或十进制。 | ||
| 159 | + | ||
| 160 | + <!-- npu="950" id58 --> | ||
| 161 | + > [!NOTE]说明 | ||
| 162 | + >Ascend 950PR&950DT系列产品配置的寄存器数最多不能超过10个,取值范围是[0x0, 0x7FFFFFFF]。 | ||
| 163 | + <!-- end id58 --> | ||
| 164 | + | ||
| 158 | 默认值: | 165 | 默认值: |
| 159 | 166 | ||
| 160 | <!-- npu="310b" id13 --> | 167 | <!-- npu="310b" id13 --> |
| @@ -178,12 +185,6 @@ AI Core性能指标采集项。task_time或task_trace配置为on、l1或l2时, | |||
| 178 | 185 | ||
| 179 | <!-- @ref: oam-tools/res/docs/zh/profiling/other_method/with_acljson_config_file_res.md#id00001 --> | 186 | <!-- @ref: oam-tools/res/docs/zh/profiling/other_method/with_acljson_config_file_res.md#id00001 --> |
| 180 | 187 | ||
| 181 | -支持自定义需要采集的寄存器,例如:"aic_metrics":"Custom:0x49,0x8,0x15,0x1b,0x64,0x10"。 | ||
| 182 | - | ||
| 183 | -- Custom字段表示自定义类型,配置为具体的寄存器值,范围[0x1, 0x7FFFFFFF]。并非所有的可取值都有对应的PMU寄存器,若配置的值无对应PMU寄存器,则采集结果可能为0。 | ||
| 184 | -- 配置的寄存器数最多不能超过8个,寄存器通过“,”区分开。 | ||
| 185 | -- 寄存器的值支持十六进制或十进制。 | ||
| 186 | - | ||
| 187 | ### l2 | 188 | ### l2 |
| 188 | 189 | ||
| 189 | 控制L2 Cache命中率和TLB页表缓存命中率采集开关,可选on或off,默认为off。若在aclgraph场景执行模型阶段开启Profiling,则该采集项无法生效。 | 190 | 控制L2 Cache命中率和TLB页表缓存命中率采集开关,可选on或off,默认为off。若在aclgraph场景执行模型阶段开启Profiling,则该采集项无法生效。 |
| @@ -17,6 +17,7 @@ | |||
| 17 | #define PROF_ACP_PLUGIN_H | 17 | #define PROF_ACP_PLUGIN_H |
| 18 | #include <cstdint> | 18 | #include <cstdint> |
| 19 | #include <map> | 19 | #include <map> |
| 20 | +#include <mutex> | ||
| 20 | #include <string> | 21 | #include <string> |
| 21 | #include <vector> | 22 | #include <vector> |
| 22 | #include "singleton/singleton_tool.h" | 23 | #include "singleton/singleton_tool.h" |
| @@ -102,6 +103,7 @@ private: | |||
| 102 | RtMemcpyFunc rtMemcpy_{nullptr}; | 103 | RtMemcpyFunc rtMemcpy_{nullptr}; |
| 103 | MsprofGetInjectionFuncT msprofGetInjectionFunc_{nullptr}; | 104 | MsprofGetInjectionFuncT msprofGetInjectionFunc_{nullptr}; |
| 104 | std::map<std::string, ApiStubInfo> apiStubInfoMap_; | 105 | std::map<std::string, ApiStubInfo> apiStubInfoMap_; |
| 106 | + std::mutex apiStubMutex_; | ||
| 105 | }; | 107 | }; |
| 106 | 108 | ||
| 107 | } // namespace Acp | 109 | } // namespace Acp |
| @@ -27,6 +27,8 @@ using namespace analysis::dvvp::common::error; | |||||||||||||||||||
| 27 | using namespace analysis::dvvp::common::utils; | 27 | using namespace analysis::dvvp::common::utils; | ||||||||||||||||
| 28 | 28 | ||||||||||||||||||
| 29 | static const char RUNTIME_LIB_PATH[] = "libruntime.so"; | 29 | static const char RUNTIME_LIB_PATH[] = "libruntime.so"; | ||||||||||||||||
| 30 | +static const char ACL_API_LIB_PATH[] = "libacl_rt.so"; | ||||||||||||||||||
| 31 | +static const std::set<std::string> g_aclApiStubSet = {"aclrtBinaryGetDevAddress", "aclrtFunctionGetBinary"}; | ||||||||||||||||||
| 30 | 32 | ||||||||||||||||||
| 31 | static std::set<std::string> g_pluginApiStubSet = { | 33 | static std::set<std::string> g_pluginApiStubSet = { | ||||||||||||||||
| 32 | "rtSetDevice", | 34 | "rtSetDevice", | ||||||||||||||||
| @@ -61,15 +63,34 @@ AcpApiPlugin::~AcpApiPlugin() | |||||||||||||||||||
| 61 | } | 63 | } | ||||||||||||||||
| 62 | } | 64 | } | ||||||||||||||||
| 63 | 65 | ||||||||||||||||||
| 66 | +static VOID_PTR LoadAclApiStubAddr(const std::string& funcName) | ||||||||||||||||||
| 67 | +{ | ||||||||||||||||||
| 68 | + VOID_PTR aclApiLibHandle = dlopen(ACL_API_LIB_PATH, RTLD_LAZY | RTLD_NOLOAD); | ||||||||||||||||||
| 69 | + if (aclApiLibHandle == nullptr) { | ||||||||||||||||||
| 70 | + const char* dlError = dlerror(); | ||||||||||||||||||
| 71 | + MSPROF_LOGW("Dlopen api from %s failed, dlopen error: %s", ACL_API_LIB_PATH, dlError == nullptr ? "" : dlError); | ||||||||||||||||||
| 72 | + return nullptr; | ||||||||||||||||||
| 73 | + } | ||||||||||||||||||
| 74 | + | ||||||||||||||||||
| 75 | + VOID_PTR addr = dlsym(aclApiLibHandle, funcName.c_str()); | ||||||||||||||||||
| 76 | + (void)dlclose(aclApiLibHandle); | ||||||||||||||||||
| 77 | + return addr; | ||||||||||||||||||
| 78 | +} | ||||||||||||||||||
| 79 | + | ||||||||||||||||||
| 64 | void AcpApiPlugin::LoadRuntimeApi() | 80 | void AcpApiPlugin::LoadRuntimeApi() | ||||||||||||||||
| 65 | { | 81 | { | ||||||||||||||||
| 66 | FUNRET_CHECK_EXPR_ACTION(acpRuntimeLibHandle_ == nullptr, return, "Runtime handle is nullptr, load api failed."); | 82 | FUNRET_CHECK_EXPR_ACTION(acpRuntimeLibHandle_ == nullptr, return, "Runtime handle is nullptr, load api failed."); | ||||||||||||||||
| 67 | for (auto& it : g_pluginApiStubSet) { | 83 | for (auto& it : g_pluginApiStubSet) { | ||||||||||||||||
| 68 | - auto addr = dlsym(acpRuntimeLibHandle_, it.c_str()); | 84 | + const bool isAclApi = g_aclApiStubSet.find(it) != g_aclApiStubSet.cend(); | ||||||||||||||||
| 69 | - FUNRET_CHECK_EXPR_ACTION_LOGW( | 85 | + VOID_PTR addr = isAclApi ? LoadAclApiStubAddr(it) : nullptr; | ||||||||||||||||
【严重】【Major】libacl_rt 晚加载时 ACL 符号仍会一次性缺失
【问题】 ![]() ![]() | |||||||||||||||||||
| 70 | - addr == nullptr, continue, "Unable to load API %s from %s.", it.c_str(), RUNTIME_LIB_PATH); | 86 | + const char* libName = isAclApi ? ACL_API_LIB_PATH : RUNTIME_LIB_PATH; | ||||||||||||||||
| 87 | + if (addr == nullptr) { | ||||||||||||||||||
| 88 | + addr = dlsym(acpRuntimeLibHandle_, it.c_str()); | ||||||||||||||||||
| 89 | + libName = RUNTIME_LIB_PATH; | ||||||||||||||||||
| 90 | + } | ||||||||||||||||||
| 91 | + FUNRET_CHECK_EXPR_ACTION_LOGW(addr == nullptr, continue, "Unable to load API %s from %s.", it.c_str(), libName); | ||||||||||||||||||
🟡 Medium Priority 变更点: 影响:修改前这两个 API 是从 libruntime.so 解析的。若运行环境的库布局仍是这两个符号由 libruntime.so 导出(历史 CANN 版本、或 libacl_rt.so 尚未被加载/不存在—— 失败模式: 建议:对 ACL 符号先试 libacl_rt.so,解析失败时回退到 acpRuntimeLibHandle_(libruntime.so);同样对 rt 符号可选地用 acl_rt 句柄做兜底。日志应反映真正解析成功的库。 Suggestions
![]() ![]() Incorrect? zhengkai 12 days ago Comments: 12 days ago Comments: ![]() ![]() | |||||||||||||||||||
| 71 | 92 | ||||||||||||||||||
| 72 | - MSPROF_LOGI("Load api[%s] from %s success.", it.c_str(), RUNTIME_LIB_PATH); | 93 | + MSPROF_LOGI("Load api[%s] from %s success.", it.c_str(), libName); | ||||||||||||||||
| 73 | apiStubInfoMap_.insert({it, {it, addr}}); | 94 | apiStubInfoMap_.insert({it, {it, addr}}); | ||||||||||||||||
| 74 | } | 95 | } | ||||||||||||||||
| 75 | 96 | ||||||||||||||||||
| @@ -146,13 +167,27 @@ rtError_t AcpApiPlugin::ApiGetBinaryData(aclrtBinHandle handle, std::vector<uint | |||||||||||||||||||
| 146 | VOID_PTR AcpApiPlugin::GetPluginApiStubFunc(const std::string funcName) | 167 | VOID_PTR AcpApiPlugin::GetPluginApiStubFunc(const std::string funcName) | ||||||||||||||||
| 147 | { | 168 | { | ||||||||||||||||
| 148 | ProfAPI::PthreadOnce(&apiLoadFlag_, []() -> void { AcpApiPlugin::instance()->LoadRuntimeApi(); }); | 169 | ProfAPI::PthreadOnce(&apiLoadFlag_, []() -> void { AcpApiPlugin::instance()->LoadRuntimeApi(); }); | ||||||||||||||||
| 149 | - auto it = apiStubInfoMap_.find(funcName); | 170 | + { | ||||||||||||||||
| 150 | - if (it == apiStubInfoMap_.cend()) { | 171 | + const std::lock_guard<std::mutex> lock(apiStubMutex_); | ||||||||||||||||
| 151 | - MSPROF_LOGE("Can't find api %s", funcName.c_str()); | 172 | + auto it = apiStubInfoMap_.find(funcName); | ||||||||||||||||
| 152 | - return nullptr; | 173 | + if (it != apiStubInfoMap_.cend()) { | ||||||||||||||||
| 174 | + return it->second.funcAddr; | ||||||||||||||||||
| 175 | + } | ||||||||||||||||||
| 176 | + | ||||||||||||||||||
| 177 | + // libacl_rt may be loaded after the one-time runtime API preload. Retry ACL wrappers | ||||||||||||||||||
| 178 | + // lazily so late loading can recover without resetting the process-wide once flag. | ||||||||||||||||||
| 179 | + if (g_aclApiStubSet.find(funcName) != g_aclApiStubSet.cend()) { | ||||||||||||||||||
| 180 | + VOID_PTR addr = LoadAclApiStubAddr(funcName); | ||||||||||||||||||
【建议】懒加载重试在持有 apiStubMutex_ 的情况下调用 LoadAclApiStubAddr,其内部执行 dlopen(RTLD_NOLOAD)/dlsym/dlclose,即拿自家的互斥量再去获取动态加载器的全局锁。本 PR 面向的注入场景里 libacl_rt 可能正被业务线程 dlopen:该线程持有 loader 锁、库构造或依赖初始化若触发任何走 GetPluginApiStubFunc 的挂钩调用,就要反过来等 apiStubMutex_,两条加锁顺序相反的路径一旦交错就是谁也走不下去的死锁,且 hang 在 dl 层基本无法用常规日志定位。建议把 dlopen/dlsym/dlclose 移到锁外执行(先在锁外解析出地址,再持锁做 map 查重与插入),使 apiStubMutex_ 只保护 std::map 的读写。 ![]() ![]() zhengkai 5 days ago Comments: 5 days ago Comments: ![]() ![]() | |||||||||||||||||||
| 181 | + if (addr != nullptr) { | ||||||||||||||||||
| 182 | + MSPROF_LOGI("Load api[%s] from %s success after retry.", funcName.c_str(), ACL_API_LIB_PATH); | ||||||||||||||||||
| 183 | + apiStubInfoMap_.insert({funcName, {funcName, addr}}); | ||||||||||||||||||
级别:严重 问题:懒加载重试只回填 apiStubInfoMap_,没有同步刷新 LoadRuntimeApi 一次性预加载时缓存的成员函数指针(尤其 aclrtBinaryGetDevAddress_),ApiGetBinaryData 等内部路径仍读取旧缓存。 影响:GetPluginApiStubFunc 能恢复 ACL 包装符号,但二进制数据获取等内部路径仍拿不到函数指针,PR 想修复的 libacl_rt.so 晚加载场景没有完全恢复,需要重启进程。 修复建议:在懒加载重试成功后、同一把 apiStubMutex_ 保护下同步给 aclrtBinaryGetDevAddress_ 等对应成员赋值;或让 Api* 统一改为通过 GetPluginApiStubFunc 按名取址。补充“首次未加载、随后加载成功”后直接调用 ApiGetBinaryData 的 UT。 依据:触发条件:进程启动时 libruntime.so 已加载、libacl_rt.so 尚未加载,首次 LoadRuntimeApi 解析 aclrtBinaryGetDevAddress 失败并把 aclrtBinaryGetDevAddress_ 留为 nullptr;随后 libacl_rt.so 被加载,调用 GetPluginApiStubFunc("aclrtBinaryGetDevAddress") 触发懒加载成功,但再调用 ApiGetBinaryData() 等依赖该成员的 Api* 路径时成员仍为 nullptr。 判断依据:当前新侧代码中懒加载分支只有 apiStubInfoMap_.insert 和 return addr,没有任何成员指针赋值;而 LoadRuntimeApiForTest 在调用 LoadRuntimeApi() 前专门清空 aclrtBinaryGetDevAddress_ 等成员,说明这些成员是由 LoadRuntimeApi 一次性填充的缓存,不是每次通过 map 查询。因此晚加载重试不会更新成员,Api* 内部路径仍会读到 nullptr。 src/msprof/collector/dvvp/acp/src/acp_api_plugin.cpp:210: apiStubInfoMap_.insert({funcName, {funcName, addr}}); src/msprof/collector/dvvp/acp/src/acp_api_plugin.cpp:107: aclrtBinaryGetDevAddress_ = nullptr; src/msprof/collector/dvvp/acp/src/acp_api_plugin.cpp:110: LoadRuntimeApi(); 反证检查:检查过的反例是:若 Api* 每次调用都重新走 GetPluginApiStubFunc,则懒加载后会自动恢复;但这样 aclrtBinaryGetDevAddress_、rtMemcpy_ 等成员就没有消费者,且测试中无需在 LoadRuntimeApi 前专门置空,与现有代码设计矛盾。新增 UT 只断言 GetPluginApiStubFunc 的返回值,未覆盖 Api* 路径,不能证明成员缓存已恢复。 ![]() ![]() | |||||||||||||||||||
| 184 | + return addr; | ||||||||||||||||||
| 185 | + } | ||||||||||||||||||
| 186 | + } | ||||||||||||||||||
| 153 | } | 187 | } | ||||||||||||||||
| 154 | 188 | ||||||||||||||||||
| 155 | - return it->second.funcAddr; | 189 | + MSPROF_LOGE("Can't find api %s", funcName.c_str()); | ||||||||||||||||
| 190 | + return nullptr; | ||||||||||||||||||
| 156 | } | 191 | } | ||||||||||||||||
| 157 | 192 | ||||||||||||||||||
| 158 | void* AcpApiPlugin::GetMsprofInjectionFunc(uint32_t type) | 193 | void* AcpApiPlugin::GetMsprofInjectionFunc(uint32_t type) | ||||||||||||||||
| @@ -200,6 +200,10 @@ bool ParamValidation::CheckAicoreMetricsIsValid(const std::string& aicoreMetrics | |||
| 200 | MSPROF_LOGE("The aic_metrics[%s] of input config is invalid", aicoreMetrics.c_str()); | 200 | MSPROF_LOGE("The aic_metrics[%s] of input config is invalid", aicoreMetrics.c_str()); |
| 201 | return false; | 201 | return false; |
| 202 | } | 202 | } |
| 203 | + const std::vector<std::string> eventsList = Utils::Split(aicoreEvent, false, "", ","); | ||
| 204 | + if (!CheckAiCoreEventsIsValid(eventsList)) { | ||
| 205 | + return false; | ||
| 206 | + } | ||
| 203 | return true; | 207 | return true; |
| 204 | } | 208 | } |
| 205 | auto featureMetrics = Platform::instance()->PmuToFeature(aicoreMetrics); | 209 | auto featureMetrics = Platform::instance()->PmuToFeature(aicoreMetrics); |
| @@ -1159,11 +1163,11 @@ bool ParamValidation::CheckAiCoreEventsIsValid(const std::vector<std::string>& e | |||
| 1159 | maxEvent = maxAiPmuEvent; | 1163 | maxEvent = maxAiPmuEvent; |
| 1160 | } | 1164 | } |
| 1161 | for (uint32_t i = 0; i < events.size(); ++i) { | 1165 | for (uint32_t i = 0; i < events.size(); ++i) { |
| 1162 | - const int32_t eventVal = strtol(events[i].c_str(), nullptr, BASE_HEX); | 1166 | + const int64_t parsedEvent = strtoll(events[i].c_str(), nullptr, BASE_HEX); |
| 1163 | - if (eventVal < minEvent || eventVal > maxEvent) { | 1167 | + if (parsedEvent < static_cast<int64_t>(minEvent) || parsedEvent > static_cast<int64_t>(maxEvent)) { |
| 1164 | MSPROF_LOGE( | 1168 | MSPROF_LOGE( |
| 1165 | - "ai core event[0x%x] out of range1-%d(0x1-0x%x). please check ai core pmu event.", eventVal, maxEvent, | 1169 | + "ai core event[%s] out of range1-%d(0x1-0x%x). please check ai core pmu event.", events[i].c_str(), |
| 1166 | - maxEvent); | 1170 | + maxEvent, maxEvent); |
| 1167 | return false; | 1171 | return false; |
| 1168 | } | 1172 | } |
| 1169 | } | 1173 | } |
| @@ -1994,6 +1994,10 @@ std::string InputParser::GeneratePrompts() const | |||
| 1994 | result << metrics; | 1994 | result << metrics; |
| 1995 | } | 1995 | } |
| 1996 | result << "]"; | 1996 | result << "]"; |
| 1997 | + const std::string minEvent = Platform::instance()->CheckIfSupport(PLATFORM_AICORE_EVENT_FROM_ZERO) ? "0x0" : "0x1"; | ||
| 1998 | + const std::string maxEventNum = std::to_string(Platform::instance()->GetMaxMonitorNumber()); | ||
| 1999 | + result << " or Custom:<event-list>. Custom event list supports hexadecimal or decimal integers in the range [" | ||
| 2000 | + << minEvent << ", 0x7FFFFFFF], separated by comma, up to " << maxEventNum << " events."; | ||
| 1997 | return result.str(); | 2001 | return result.str(); |
| 1998 | } | 2002 | } |
| 1999 | 2003 | ||
| @@ -2468,11 +2472,15 @@ void ArgsManager::AddAicMetricsArgs() | |||
| 2468 | if (Platform::instance()->CheckIfSupport(PLATFORM_TASK_MEMORY_ACCESS_PMU)) { | 2472 | if (Platform::instance()->CheckIfSupport(PLATFORM_TASK_MEMORY_ACCESS_PMU)) { |
| 2469 | memoryAccess = ", MemoryAccess"; | 2473 | memoryAccess = ", MemoryAccess"; |
| 2470 | } | 2474 | } |
| 2475 | + const std::string minEvent = Platform::instance()->CheckIfSupport(PLATFORM_AICORE_EVENT_FROM_ZERO) ? "0x0" : "0x1"; | ||
| 2476 | + const std::string maxEventNum = std::to_string(Platform::instance()->GetMaxMonitorNumber()); | ||
| 2471 | Args aicMetricsArgs = { | 2477 | Args aicMetricsArgs = { |
| 2472 | "aic-metrics", | 2478 | "aic-metrics", |
| 2473 | "The aic metrics groups, include ArithmeticUtilization, PipeUtilization" + pipExe + ", Memory, MemoryL0" + | 2479 | "The aic metrics groups, include ArithmeticUtilization, PipeUtilization" + pipExe + ", Memory, MemoryL0" + |
| 2474 | - resource + ", MemoryUB" + l2Cache + memoryAccess + ".\n" + "\t\t\t\t\t\t the default value is " + option + | 2480 | + resource + ", MemoryUB" + l2Cache + memoryAccess + " or Custom:<event-list>.\n" + |
| 2475 | - ".", | 2481 | + "\t\t\t\t\t\t Custom event list supports hexadecimal or decimal integers in the range [" + minEvent + |
| 2482 | + ", 0x7FFFFFFF], separated by comma, up to " + maxEventNum + " events.\n" + | ||
| 2483 | + "\t\t\t\t\t\t the default value is " + option + ".", | ||
| 2476 | option}; | 2484 | option}; |
| 2477 | argsList_.push_back(aicMetricsArgs); | 2485 | argsList_.push_back(aicMetricsArgs); |
| 2478 | } | 2486 | } |
| @@ -142,13 +142,18 @@ void Uploader::Run(const error_message::ErrorManagerContext& errorContext) | |||
| 142 | sentLen); | 142 | sentLen); |
| 143 | } | 143 | } |
| 144 | } else { | 144 | } else { |
| 145 | - if (transport_->SendBuffer(fileChunkReq) != PROFILING_SUCCESS) { | 145 | + const int32_t ret = transport_->SendBuffer(fileChunkReq); |
| 146 | - MSPROF_LOGE("Failed to upload data"); | 146 | + if (ret != PROFILING_SUCCESS) { |
| 147 | - MSPROF_INNER_ERROR("EK9999", "Failed to upload data"); | 147 | + MSPROF_LOGE( |
| 148 | + "Failed to upload file chunk, id: %s, fileName: %s, data_len: %zu bytes, ret: %d", | ||
| 149 | + fileChunkReq->id.c_str(), fileChunkReq->fileName.c_str(), fileChunkReq->chunkSize, ret); | ||
| 150 | + MSPROF_INNER_ERROR( | ||
| 151 | + "EK9999", "Failed to upload file chunk, id: %s, fileName: %s, data_len: %zu bytes, ret: %d", | ||
| 152 | + fileChunkReq->id.c_str(), fileChunkReq->fileName.c_str(), fileChunkReq->chunkSize, ret); | ||
| 148 | } | 153 | } |
| 149 | if (pipeTransport_ != nullptr && pipeTransport_->IsRegisterRawDataCallback()) { | 154 | if (pipeTransport_ != nullptr && pipeTransport_->IsRegisterRawDataCallback()) { |
| 150 | - int32_t ret = pipeTransport_->SendBuffer(fileChunkReq); | 155 | + int32_t pipeRet = pipeTransport_->SendBuffer(fileChunkReq); |
| 151 | - if (ret != PROFILING_SUCCESS) { | 156 | + if (pipeRet != PROFILING_SUCCESS) { |
| 152 | MSPROF_LOGE("PipeTransport failed to upload raw data"); | 157 | MSPROF_LOGE("PipeTransport failed to upload raw data"); |
| 153 | } | 158 | } |
| 154 | } | 159 | } |
| @@ -17,8 +17,10 @@ | |||
| 17 | #include <string> | 17 | #include <string> |
| 18 | #include "mockcpp/mockcpp.hpp" | 18 | #include "mockcpp/mockcpp.hpp" |
| 19 | #include "gtest/gtest.h" | 19 | #include "gtest/gtest.h" |
| 20 | +#define private public | ||
| 20 | #include "acp_aclrt_injection_tool.h" | 21 | #include "acp_aclrt_injection_tool.h" |
| 21 | #include "acp_api_plugin.h" | 22 | #include "acp_api_plugin.h" |
| 23 | +#undef private | ||
| 22 | #include "acp_manager_tool.h" | 24 | #include "acp_manager_tool.h" |
| 23 | #include "acp_pipe_transfer_tool.h" | 25 | #include "acp_pipe_transfer_tool.h" |
| 24 | #include "prof_params.h" | 26 | #include "prof_params.h" |
| @@ -34,6 +36,8 @@ using namespace analysis::dvvp::common::utils; | |||
| 34 | namespace { | 36 | namespace { |
| 35 | constexpr int32_t HOOK_COUNT_IN_TEST = 13; | 37 | constexpr int32_t HOOK_COUNT_IN_TEST = 13; |
| 36 | 38 | ||
| 39 | +void ResetAcpApiPluginForTest(); | ||
| 40 | + | ||
| 37 | int32_t g_originStub() { return 0; } | 41 | int32_t g_originStub() { return 0; } |
| 38 | 42 | ||
| 39 | std::map<std::string, AclrtApiFuncT> g_hookMap; | 43 | std::map<std::string, AclrtApiFuncT> g_hookMap; |
| @@ -41,6 +45,8 @@ std::map<std::string, AclrtApiFuncT> g_originMap; | |||
| 41 | std::map<std::string, bool> g_getBeforeSet; | 45 | std::map<std::string, bool> g_getBeforeSet; |
| 42 | bool g_tableReady = false; | 46 | bool g_tableReady = false; |
| 43 | bool g_originMissing = false; | 47 | bool g_originMissing = false; |
| 48 | +bool g_aclApiInRuntimeOnly = false; | ||
| 49 | +bool g_aclRtLoaded = false; | ||
| 44 | int32_t g_setCallCount = 0; | 50 | int32_t g_setCallCount = 0; |
| 45 | int32_t g_getCallCount = 0; | 51 | int32_t g_getCallCount = 0; |
| 46 | 52 | ||
| @@ -51,11 +57,54 @@ void ResetMockState() | |||
| 51 | g_getBeforeSet.clear(); | 57 | g_getBeforeSet.clear(); |
| 52 | g_tableReady = false; | 58 | g_tableReady = false; |
| 53 | g_originMissing = false; | 59 | g_originMissing = false; |
| 60 | + g_aclApiInRuntimeOnly = false; | ||
| 61 | + g_aclRtLoaded = false; | ||
| 54 | g_setCallCount = 0; | 62 | g_setCallCount = 0; |
| 55 | g_getCallCount = 0; | 63 | g_getCallCount = 0; |
| 56 | ResetAclrtHooksForTest(); | 64 | ResetAclrtHooksForTest(); |
| 57 | } | 65 | } |
| 58 | 66 | ||
| 67 | +class AclApiPluginStateGuard { | ||
| 68 | +public: | ||
| 69 | + ~AclApiPluginStateGuard() { ResetAcpApiPluginForTest(); } | ||
| 70 | +}; | ||
| 71 | + | ||
| 72 | +class AcpApiPluginTestAccessor { | ||
| 73 | +public: | ||
| 74 | + static void Prepare(AcpApiPlugin& plugin, VOID_PTR runtimeHandle) | ||
| 75 | + { | ||
| 76 | + Reset(plugin); | ||
| 77 | + plugin.acpRuntimeLibHandle_ = runtimeHandle; | ||
| 78 | + Reload(plugin); | ||
| 79 | + } | ||
| 80 | + | ||
| 81 | + static void Reset(AcpApiPlugin& plugin) | ||
| 82 | + { | ||
| 83 | + plugin.apiLoadFlag_ = PTHREAD_ONCE_INIT; | ||
| 84 | + plugin.acpRuntimeLibHandle_ = nullptr; | ||
| 85 | + plugin.apiStubInfoMap_.clear(); | ||
| 86 | + plugin.rtStreamSynchronize_ = nullptr; | ||
| 87 | + plugin.rtGetBinaryDeviceBaseAddress_ = nullptr; | ||
| 88 | + plugin.aclrtBinaryGetDevAddress_ = nullptr; | ||
| 89 | + plugin.rtMemcpy_ = nullptr; | ||
| 90 | + plugin.msprofGetInjectionFunc_ = nullptr; | ||
| 91 | + } | ||
| 92 | + | ||
| 93 | +private: | ||
| 94 | + static void Reload(AcpApiPlugin& plugin) | ||
| 95 | + { | ||
| 96 | + plugin.apiStubInfoMap_.clear(); | ||
| 97 | + plugin.rtStreamSynchronize_ = nullptr; | ||
| 98 | + plugin.rtGetBinaryDeviceBaseAddress_ = nullptr; | ||
| 99 | + plugin.aclrtBinaryGetDevAddress_ = nullptr; | ||
| 100 | + plugin.rtMemcpy_ = nullptr; | ||
| 101 | + plugin.msprofGetInjectionFunc_ = nullptr; | ||
| 102 | + plugin.LoadRuntimeApi(); | ||
| 103 | + } | ||
| 104 | +}; | ||
| 105 | + | ||
| 106 | +void ResetAcpApiPluginForTest() { AcpApiPluginTestAccessor::Reset(*AcpApiPlugin::instance()); } | ||
| 107 | + | ||
| 59 | int32_t MockSetFunc(const char* name, AclrtApiFuncT func) | 108 | int32_t MockSetFunc(const char* name, AclrtApiFuncT func) |
| 60 | { | 109 | { |
| 61 | if (!g_tableReady) { | 110 | if (!g_tableReady) { |
| @@ -121,6 +170,46 @@ int32_t g_functionGetBinaryStub(const void*, aclrtBinHandle* binHandle) | |||
| 121 | return ACL_SUCCESS; | 170 | return ACL_SUCCESS; |
| 122 | } | 171 | } |
| 123 | 172 | ||
| 173 | +int32_t g_originApiStub() { return 0; } | ||
| 174 | + | ||
| 175 | +int32_t g_mockLibRuntime; | ||
| 176 | +int32_t g_mockLibAclRt; | ||
| 177 | + | ||
| 178 | +void* MockApiDlopen(const char* fileName, int mode) | ||
| 179 | +{ | ||
| 180 | + (void)mode; | ||
| 181 | + if (std::string(fileName) == "libruntime.so") { | ||
| 182 | + return &g_mockLibRuntime; | ||
| 183 | + } | ||
| 184 | + if (std::string(fileName) == "libacl_rt.so") { | ||
| 185 | + return g_aclRtLoaded ? &g_mockLibAclRt : nullptr; | ||
| 186 | + } | ||
| 187 | + return nullptr; | ||
| 188 | +} | ||
| 189 | + | ||
| 190 | +void* MockApiDlsym(void* handle, const char* symbol) | ||
| 191 | +{ | ||
| 192 | + if (handle == &g_mockLibRuntime) { | ||
| 193 | + const bool isRtApi = std::string(symbol) == "rtStreamSynchronize"; | ||
| 194 | + const bool isAclApi = | ||
| 195 | + (std::string(symbol) == "aclrtBinaryGetDevAddress") || (std::string(symbol) == "aclrtFunctionGetBinary"); | ||
| 196 | + return (isRtApi || (g_aclApiInRuntimeOnly && isAclApi)) ? reinterpret_cast<VOID_PTR>(&g_originApiStub) : | ||
| 197 | + nullptr; | ||
| 198 | + } | ||
| 199 | + if (handle == &g_mockLibAclRt) { | ||
| 200 | + const bool isAclApi = | ||
| 201 | + (std::string(symbol) == "aclrtBinaryGetDevAddress") || (std::string(symbol) == "aclrtFunctionGetBinary"); | ||
| 202 | + return (!g_aclApiInRuntimeOnly && isAclApi) ? reinterpret_cast<VOID_PTR>(&g_functionGetBinaryStub) : nullptr; | ||
| 203 | + } | ||
| 204 | + return nullptr; | ||
| 205 | +} | ||
| 206 | + | ||
| 207 | +int MockApiDlclose(void* handle) | ||
| 208 | +{ | ||
| 209 | + (void)handle; | ||
| 210 | + return 0; | ||
| 211 | +} | ||
| 212 | + | ||
| 124 | } // namespace | 213 | } // namespace |
| 125 | 214 | ||
| 126 | class AcpAclrtInjectionUtest : public testing::Test { | 215 | class AcpAclrtInjectionUtest : public testing::Test { |
| @@ -454,6 +543,60 @@ TEST_F(AcpAclrtInjectionUtest, GetPluginApiStubFuncNotFound) | |||
| 454 | SUCCEED(); | 543 | SUCCEED(); |
| 455 | } | 544 | } |
| 456 | 545 | ||
| 546 | +TEST_F(AcpAclrtInjectionUtest, LoadRuntimeApiResolvesAclApiFromAclRt) | ||
| 547 | +{ | ||
| 548 | + // libruntime.so 只有 rt 层符号;aclrt* 公开包装函数在 libacl_rt.so 中。 | ||
| 549 | + g_aclRtLoaded = true; | ||
| 550 | + MOCKER(dlopen).stubs().will(invoke(MockApiDlopen)); | ||
| 551 | + MOCKER(dlsym).stubs().will(invoke(MockApiDlsym)); | ||
| 552 | + MOCKER(dlclose).stubs().will(invoke(MockApiDlclose)); | ||
| 553 | + AclApiPluginStateGuard stateGuard; | ||
| 554 | + auto& plugin = *AcpApiPlugin::instance(); | ||
| 555 | + AcpApiPluginTestAccessor::Prepare(plugin, MockApiDlopen("libruntime.so", RTLD_NOW)); | ||
| 556 | + EXPECT_EQ( | ||
| 557 | + reinterpret_cast<VOID_PTR>(&g_functionGetBinaryStub), plugin.GetPluginApiStubFunc("aclrtFunctionGetBinary")); | ||
| 558 | + EXPECT_EQ( | ||
| 559 | + reinterpret_cast<VOID_PTR>(&g_functionGetBinaryStub), plugin.GetPluginApiStubFunc("aclrtBinaryGetDevAddress")); | ||
| 560 | + EXPECT_EQ(reinterpret_cast<VOID_PTR>(&g_originApiStub), plugin.GetPluginApiStubFunc("rtStreamSynchronize")); | ||
| 561 | + GlobalMockObject::verify(); | ||
🟡 Medium Priority 变更点:新增用例把共享单例 失败模式(触发条件为同一测试二进制的用例顺序):
建议:在用例/TearDown 中恢复单例状态:把 acpRuntimeLibHandle_ 置回 nullptr(或原值)、清空 apiStubInfoMap_,并把 apiLoadFlag_ 复位;使 mock 库句柄不会残留给后续用例与析构函数。 ![]() ![]() Incorrect? zhengkai 12 days ago Comments: 12 days ago Comments: ![]() ![]() | |||
| 562 | +} | ||
| 563 | + | ||
| 564 | +TEST_F(AcpAclrtInjectionUtest, LoadRuntimeApiRetriesAclApiAfterAclRtLoaded) | ||
| 565 | +{ | ||
| 566 | + // The first preload happens before libacl_rt is loaded; the later call must recover lazily. | ||
| 567 | + g_aclRtLoaded = false; | ||
| 568 | + MOCKER(dlopen).stubs().will(invoke(MockApiDlopen)); | ||
| 569 | + MOCKER(dlsym).stubs().will(invoke(MockApiDlsym)); | ||
| 570 | + MOCKER(dlclose).stubs().will(invoke(MockApiDlclose)); | ||
| 571 | + AclApiPluginStateGuard stateGuard; | ||
| 572 | + auto& plugin = *AcpApiPlugin::instance(); | ||
| 573 | + AcpApiPluginTestAccessor::Prepare(plugin, MockApiDlopen("libruntime.so", RTLD_NOW)); | ||
| 574 | + EXPECT_EQ(nullptr, plugin.GetPluginApiStubFunc("aclrtFunctionGetBinary")); | ||
| 575 | + | ||
| 576 | + g_aclRtLoaded = true; | ||
| 577 | + EXPECT_EQ( | ||
| 578 | + reinterpret_cast<VOID_PTR>(&g_functionGetBinaryStub), plugin.GetPluginApiStubFunc("aclrtFunctionGetBinary")); | ||
| 579 | + EXPECT_EQ( | ||
| 580 | + reinterpret_cast<VOID_PTR>(&g_functionGetBinaryStub), plugin.GetPluginApiStubFunc("aclrtBinaryGetDevAddress")); | ||
| 581 | + GlobalMockObject::verify(); | ||
| 582 | +} | ||
| 583 | + | ||
| 584 | +TEST_F(AcpAclrtInjectionUtest, LoadRuntimeApiFallsBackToRuntimeForLegacyAclApi) | ||
| 585 | +{ | ||
| 586 | + // 历史库布局中 aclrt* 公开包装函数仍由 libruntime.so 导出,需回退解析。 | ||
| 587 | + g_aclApiInRuntimeOnly = true; | ||
| 588 | + g_aclRtLoaded = true; | ||
| 589 | + MOCKER(dlopen).stubs().will(invoke(MockApiDlopen)); | ||
| 590 | + MOCKER(dlsym).stubs().will(invoke(MockApiDlsym)); | ||
| 591 | + MOCKER(dlclose).stubs().will(invoke(MockApiDlclose)); | ||
| 592 | + AclApiPluginStateGuard stateGuard; | ||
| 593 | + auto& plugin = *AcpApiPlugin::instance(); | ||
| 594 | + AcpApiPluginTestAccessor::Prepare(plugin, MockApiDlopen("libruntime.so", RTLD_NOW)); | ||
| 595 | + EXPECT_EQ(reinterpret_cast<VOID_PTR>(&g_originApiStub), plugin.GetPluginApiStubFunc("aclrtFunctionGetBinary")); | ||
| 596 | + EXPECT_EQ(reinterpret_cast<VOID_PTR>(&g_originApiStub), plugin.GetPluginApiStubFunc("aclrtBinaryGetDevAddress")); | ||
| 597 | + GlobalMockObject::verify(); | ||
| 598 | +} | ||
| 599 | + | ||
| 457 | TEST_F(AcpAclrtInjectionUtest, TaskStartRegistersStarsAndBiuJobs) | 600 | TEST_F(AcpAclrtInjectionUtest, TaskStartRegistersStarsAndBiuJobs) |
| 458 | { | 601 | { |
| 459 | // instrProfiling/pcSampling 均为 off 时,STARS/FFTS/BIU 三类采集任务全部注册执行 | 602 | // instrProfiling/pcSampling 均为 off 时,STARS/FFTS/BIU 三类采集任务全部注册执行 |
| @@ -774,6 +774,23 @@ TEST_F(COMMON_VALIDATION_PARAM_VALIDATION_TEST, CheckAiCoreEventsIsValidModena) | |||
| 774 | 774 | ||
| 775 | events = {"0x80000000"}; | 775 | events = {"0x80000000"}; |
| 776 | EXPECT_EQ(false, ParamValidation::instance()->CheckAiCoreEventsIsValid(events)); | 776 | EXPECT_EQ(false, ParamValidation::instance()->CheckAiCoreEventsIsValid(events)); |
| 777 | + | ||
| 778 | + events = {"0x100000001"}; | ||
| 779 | + EXPECT_EQ(false, ParamValidation::instance()->CheckAiCoreEventsIsValid(events)); | ||
| 780 | +} | ||
| 781 | + | ||
| 782 | +TEST_F(COMMON_VALIDATION_PARAM_VALIDATION_TEST, InvalidAiCoreEventLogShowsInputValue) | ||
| 783 | +{ | ||
| 784 | + MOCKER_CPP(&Platform::GetMaxMonitorNumber).stubs().will(returnValue(MODENA_MAX_MONITOR_NUM)); | ||
| 785 | + MOCKER_CPP(&Platform::GetPlatformType).stubs().will(returnValue(PlatformTypeEnum::CHIP_5162A)); | ||
| 786 | + const std::vector<std::string> events = {"0x100000001"}; | ||
| 787 | + | ||
| 788 | + testing::internal::CaptureStdout(); | ||
| 789 | + EXPECT_FALSE(ParamValidation::instance()->CheckAiCoreEventsIsValid(events)); | ||
| 790 | + const std::string log = testing::internal::GetCapturedStdout(); | ||
| 791 | + | ||
| 792 | + EXPECT_NE(std::string::npos, log.find("ai core event[0x100000001] out of range")); | ||
| 793 | + EXPECT_EQ(std::string::npos, log.find("ai core event[0x1] out of range")); | ||
| 777 | } | 794 | } |
| 778 | 795 | ||
| 779 | TEST_F(COMMON_VALIDATION_PARAM_VALIDATION_TEST, CheckParamL0L1InvalidBasicResult) | 796 | TEST_F(COMMON_VALIDATION_PARAM_VALIDATION_TEST, CheckParamL0L1InvalidBasicResult) |
| @@ -703,6 +703,80 @@ TEST_F(INPUT_PARSER_UTEST, PrintHelpShowsNtsMetricsOnTargetChip) | |||
| 703 | EXPECT_NE(std::string::npos, help.find("[0x0, 0x71b]")); | 703 | EXPECT_NE(std::string::npos, help.find("[0x0, 0x71b]")); |
| 704 | } | 704 | } |
| 705 | 705 | ||
| 706 | +TEST_F(INPUT_PARSER_UTEST, PrintHelpShowsAicMetricsCustomEvents) | ||
| 707 | +{ | ||
| 708 | + const std::string help = CaptureHelpForPlatform(PlatformType::CLOUD_TYPE); | ||
| 709 | + EXPECT_NE(std::string::npos, help.find("--aic-metrics")); | ||
| 710 | + EXPECT_NE(std::string::npos, help.find("Custom:<event-list>")); | ||
| 711 | + EXPECT_NE(std::string::npos, help.find("[0x1, 0x7FFFFFFF]")); | ||
| 712 | + EXPECT_NE(std::string::npos, help.find("up to 8 events")); | ||
| 713 | +} | ||
| 714 | + | ||
| 715 | +TEST_F(INPUT_PARSER_UTEST, InvalidAicMetricsErrorDoesNotDuplicateBracket) | ||
| 716 | +{ | ||
| 717 | + SetPlatformTypeForTest(PlatformType::CLOUD_TYPE); | ||
| 718 | + Platform::instance()->Uninit(); | ||
| 719 | + Platform::instance()->Init(); | ||
| 720 | + InputParser parser; | ||
| 721 | + MsprofCmdInfo cmdInfo = {{nullptr}}; | ||
| 722 | + cmdInfo.args[ARGS_AIC_METRICS] = "invalid"; | ||
| 723 | + | ||
| 724 | + testing::internal::CaptureStdout(); | ||
| 725 | + EXPECT_EQ(PROFILING_FAILED, parser.CheckAiCoreMetricsValid(cmdInfo, ARGS_AIC_METRICS)); | ||
| 726 | + const std::string error = testing::internal::GetCapturedStdout(); | ||
| 727 | + | ||
| 728 | + EXPECT_NE(std::string::npos, error.find("] or Custom:<event-list>")); | ||
| 729 | + EXPECT_EQ(std::string::npos, error.find("]] or Custom:<event-list>")); | ||
| 730 | + Platform::instance()->Uninit(); | ||
| 731 | +} | ||
| 732 | + | ||
| 733 | +TEST_F(INPUT_PARSER_UTEST, PrintHelpShowsAicMetricsEventLimitByPlatform) | ||
| 734 | +{ | ||
| 735 | + const std::string help = CaptureHelpForPlatform(PlatformType::CHIP_CLOUD_V3); | ||
| 736 | + EXPECT_NE(std::string::npos, help.find("up to 10 events")); | ||
| 737 | + EXPECT_EQ(std::string::npos, help.find("up to 8 events")); | ||
| 738 | +} | ||
| 739 | + | ||
| 740 | +TEST_F(INPUT_PARSER_UTEST, AicMetricsAllowsZeroCustomEventOnDavid) | ||
| 741 | +{ | ||
| 742 | + SetPlatformTypeForTest(PlatformType::CHIP_CLOUD_V3); | ||
| 743 | + Platform::instance()->Uninit(); | ||
| 744 | + Platform::instance()->Init(); | ||
| 745 | + | ||
| 746 | + InputParser parser; | ||
| 747 | + MsprofCmdInfo cmdInfo = {{nullptr}}; | ||
| 748 | + cmdInfo.args[ARGS_AIC_METRICS] = "Custom:0x0"; | ||
| 749 | + EXPECT_EQ(PROFILING_SUCCESS, parser.CheckAiCoreMetricsValid(cmdInfo, ARGS_AIC_METRICS)); | ||
| 750 | + Platform::instance()->Uninit(); | ||
| 751 | +} | ||
| 752 | + | ||
| 753 | +TEST_F(INPUT_PARSER_UTEST, AicMetricsRejectsCustomEventAboveUpperLimit) | ||
| 754 | +{ | ||
| 755 | + SetPlatformTypeForTest(PlatformType::CHIP_5162A); | ||
| 756 | + Platform::instance()->Uninit(); | ||
| 757 | + Platform::instance()->Init(); | ||
| 758 | + | ||
| 759 | + InputParser parser; | ||
| 760 | + MsprofCmdInfo cmdInfo = {{nullptr}}; | ||
| 761 | + cmdInfo.args[ARGS_AIC_METRICS] = "Custom:0x80000000"; | ||
| 762 | + EXPECT_EQ(PROFILING_FAILED, parser.CheckAiCoreMetricsValid(cmdInfo, ARGS_AIC_METRICS)); | ||
| 763 | + Platform::instance()->Uninit(); | ||
| 764 | +} | ||
| 765 | + | ||
| 766 | +TEST_F(INPUT_PARSER_UTEST, PrintHelpShowsDavidZeroEventRange) | ||
| 767 | +{ | ||
| 768 | + const std::string help = CaptureHelpForPlatform(PlatformType::CHIP_CLOUD_V3); | ||
| 769 | + EXPECT_NE(std::string::npos, help.find("[0x0, 0x7FFFFFFF]")); | ||
| 770 | + EXPECT_EQ(std::string::npos, help.find("[0x1, 0x7FFFFFFF]")); | ||
| 771 | +} | ||
| 772 | + | ||
| 773 | +TEST_F(INPUT_PARSER_UTEST, PrintHelpShowsModenaZeroEventRange) | ||
| 774 | +{ | ||
| 775 | + const std::string help = CaptureHelpForPlatform(PlatformType::CHIP_5162A); | ||
| 776 | + EXPECT_NE(std::string::npos, help.find("[0x0, 0x7FFFFFFF]")); | ||
| 777 | + EXPECT_EQ(std::string::npos, help.find("[0x1, 0x7FFFFFFF]")); | ||
| 778 | +} | ||
| 779 | + | ||
| 706 | TEST_F(INPUT_PARSER_UTEST, PrintHelpHidesNtsMetricsOnOtherPlatform) | 780 | TEST_F(INPUT_PARSER_UTEST, PrintHelpHidesNtsMetricsOnOtherPlatform) |
| 707 | { | 781 | { |
| 708 | const std::string help = CaptureHelpForPlatform(PlatformType::CLOUD_TYPE); | 782 | const std::string help = CaptureHelpForPlatform(PlatformType::CLOUD_TYPE); |
| @@ -138,6 +138,42 @@ TEST_F(UPLOADER_TEST, run_with_data) | |||
| 138 | GlobalMockObject::reset(); | 138 | GlobalMockObject::reset(); |
| 139 | } | 139 | } |
| 140 | 140 | ||
| 141 | +TEST_F(UPLOADER_TEST, UploaderFileChunkFailureMessageIncludesContext) | ||
【一般】【Normal】这条用例没有执行 Uploader::Run,只是把 uploader_tool.cpp 读成字符串再匹配日志格式串,格式串与实参不匹配、id 与 fileName 传反、失败分支走不到这类回归都检不出来,PR 描述里「UT 覆盖文件分片上传失败日志包含文件 ID、文件名、数据长度和返回码」实际没有对应验证。同文件 run_with_data 已有现成范式,可以用 MOCKER_CPP_VIRTUAL 打桩 SendBuffer(SHARED_PTR_ALIA ![]() ![]() | |||
| 142 | +{ | ||
| 143 | + GlobalMockObject::verify(); | ||
| 144 | + using namespace analysis::dvvp::transport; | ||
| 145 | + | ||
| 146 | + constexpr int32_t uploadRet = -12; | ||
| 147 | + auto chunk = std::make_shared<analysis::dvvp::ProfileFileChunk>(); | ||
| 148 | + chunk->id = "0.1"; | ||
| 149 | + chunk->fileName = "host_op_summary.csv"; | ||
| 150 | + chunk->chunkSize = 128; | ||
| 151 | + chunk->chunkModule = analysis::dvvp::common::config::PROFILING_IS_FROM_MSPROF_HOST; | ||
| 152 | + | ||
| 153 | + std::shared_ptr<Uploader> uploader(new Uploader(_transport)); | ||
| 154 | + MOCKER_CPP_VIRTUAL( | ||
| 155 | + *_transport.get(), &MsptiPipeTransport::SendBuffer, | ||
| 156 | + int32_t(MsptiPipeTransport::*)(SHARED_PTR_ALIA<analysis::dvvp::ProfileFileChunk>)) | ||
| 157 | + .stubs() | ||
| 158 | + .will(returnValue(uploadRet)); | ||
| 159 | + | ||
| 160 | + EXPECT_EQ(PROFILING_SUCCESS, uploader->Init()); | ||
| 161 | + EXPECT_EQ(PROFILING_SUCCESS, uploader->UploadData(chunk)); | ||
| 162 | + uploader->forceQuit_ = true; | ||
| 163 | + uploader->queue_->Quit(); | ||
| 164 | + auto errorContext = MsprofErrorManager::instance()->GetErrorManagerContext(); | ||
| 165 | + testing::internal::CaptureStdout(); | ||
| 166 | + uploader->Run(errorContext); | ||
| 167 | + const std::string logMsg = testing::internal::GetCapturedStdout(); | ||
| 168 | + | ||
| 169 | + EXPECT_NE(std::string::npos, logMsg.find("id: 0.1")); | ||
| 170 | + EXPECT_NE(std::string::npos, logMsg.find("fileName: host_op_summary.csv")); | ||
| 171 | + EXPECT_NE(std::string::npos, logMsg.find("data_len: 128 bytes")); | ||
| 172 | + EXPECT_NE(std::string::npos, logMsg.find("ret: -12")); | ||
| 173 | + uploader.reset(); | ||
| 174 | + GlobalMockObject::reset(); | ||
| 175 | +} | ||
| 176 | + | ||
| 141 | TEST_F(UPLOADER_TEST, Flush) | 177 | TEST_F(UPLOADER_TEST, Flush) |
| 142 | { | 178 | { |
| 143 | GlobalMockObject::verify(); | 179 | GlobalMockObject::verify(); |


dlopen失败没有打印失败原因